<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta property="og:type" content="website">
<meta property="og:title" content="苏生不惑的博客">
<meta property="og:url" content="http://yoursite.com/page/27/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="苏生不惑的博客">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/page/27/">



<meta name="referrer" content="never"> ​​​​


  <title>苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/那些你可能不知道的-PDF-工具/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/那些你可能不知道的-PDF-工具/" itemprop="url">那些你可能不知道的 PDF 工具</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:27:10+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.4k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  6 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>从网上下载了PDF文件，想转换为文字或者图片怎么办，这里分享些常用的PDF制作工具。</p>
<h3 id="smallpdf"><a href="#smallpdf" class="headerlink" title="smallpdf"></a>smallpdf</h3><p>功能一应俱全、简单好用的线上 PDF 工具 <a href="https://smallpdf.com/cn/" target="_blank" rel="noopener">https://smallpdf.com/cn/</a> ppt PDF互转，pdf Excel互转什么的都有。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8a61a3fe1ed8802a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>它还提供了Chrome扩展 <a href="https://zhaoolee.com/ChromeAppHeroes/page/032_smallpdf.html" target="_blank" rel="noopener">https://zhaoolee.com/ChromeAppHeroes/page/032_smallpdf.html</a></p>
<h3 id="pdf24"><a href="#pdf24" class="headerlink" title="pdf24"></a>pdf24</h3><p>免费且易于使用的在线PDF工具 <a href="https://tools.pdf24.org/zh/" target="_blank" rel="noopener">https://tools.pdf24.org/zh/</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-493ca9080245e8a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>PDF压缩合并编辑转换都有。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3bc5f9e7349eb89c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="ilovepdf"><a href="#ilovepdf" class="headerlink" title="ilovepdf"></a>ilovepdf</h3><p> 完全免费的PDF文件在线管理工具，其功能包括：合并PDF文件、拆分PDF文件、压缩PDF文件、Office文件转换为PDF文件、PDF文件转换为JPG图片、JPG图片转换为PDF文件，无需安装。<a href="https://www.ilovepdf.com/zh-cn，对应的还有图片处理的https://www.iloveimg.com/" target="_blank" rel="noopener">https://www.ilovepdf.com/zh-cn，对应的还有图片处理的https://www.iloveimg.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-e8666325f8bfba77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-73bb3373e94988f4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="docsmall"><a href="#docsmall" class="headerlink" title="docsmall"></a>docsmall</h3><p>由 INTERVAL DESIGN 设计开发的在线文件处理工具，无需下载软件，通过云端服务<br>上传、处理、下载简单三步即可完成操作，目前已上线图片压缩、PDF压缩、PDF合并、PDF分割功能<a href="https://docsmall.com/" target="_blank" rel="noopener">https://docsmall.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-73617344f82289c2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="alltoall"><a href="#alltoall" class="headerlink" title="alltoall"></a>alltoall</h3><p>免费的在线格式转换工具,支持200+格式的文件在线转换，且完全免费。<a href="http://www.alltoall.net/document-pdf/" target="_blank" rel="noopener">http://www.alltoall.net/document-pdf/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-39d0c48c7cc1a7f5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>###PickFrom<br>一应俱全，简单便捷的在线工具 <a href="https://zh.pickfrom.net/" target="_blank" rel="noopener">https://zh.pickfrom.net/</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-a9c485ee8228b1e5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>将公众号文章转PDF，预览效果 <a href="https://zh.pickfrom.net/weixin2pdf" target="_blank" rel="noopener">https://zh.pickfrom.net/weixin2pdf</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-132f872813af6057.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>###hipdf<br>一站式在线PDF解决方案<a href="https://www.hipdf.cn/" target="_blank" rel="noopener">https://www.hipdf.cn/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-a6ef8985d0b904a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="pdf-io"><a href="#pdf-io" class="headerlink" title="pdf.io"></a>pdf.io</h3><p><a href="https://pdf.io/tw/" target="_blank" rel="noopener">https://pdf.io/tw/</a> 这个界面只有繁体中文，不过功能一样的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-500f085edafd072b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="PDF派"><a href="#PDF派" class="headerlink" title="PDF派"></a>PDF派</h3><p>好用的PDF在线工具，完全免费<a href="https://www.pdfpai.com/" target="_blank" rel="noopener">https://www.pdfpai.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-af8010e4878fe6e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-c75a005fd904fd68.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="第三方网站"><a href="#第三方网站" class="headerlink" title="第三方网站"></a>第三方网站</h3><p>有些第三方网站集成了这些工具，比如 <a href="http://www.nicetool.net/" target="_blank" rel="noopener">http://www.nicetool.net/</a> 搜索pdf<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8db0fbefb0678fc0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>第一个PDF转图片 <a href="http://www.nicetool.net/app/pdf2image.html" target="_blank" rel="noopener">http://www.nicetool.net/app/pdf2image.html</a> 每张PPT转为一张图片，效果如图。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3f321d355c09e3a3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>类似的还有<a href="http://www.gjw123.com/search.html?query=pdf" target="_blank" rel="noopener">http://www.gjw123.com/search.html?query=pdf</a> <a href="https://www.toolnb.com/" target="_blank" rel="noopener">https://www.toolnb.com/</a>  我试了下效果不错。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c3b14b58e640bb28.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="Office2PDF"><a href="#Office2PDF" class="headerlink" title="Office2PDF"></a>Office2PDF</h3><p>转换选定目录下所有doc/docx/ppt/pptx到PDF, 需要安装有Office 2010或Office2013, 直接运行Office2PDF.ahk即可, 会保留原始目录结构。<br>下载地址<a href="https://github.com/icylogic/Office2PDF/releases/download/0.1/Office2PDF.exe" target="_blank" rel="noopener">https://github.com/icylogic/Office2PDF/releases/download/0.1/Office2PDF.exe</a><br> 类似的还有<a href="https://github.com/cxgreat2014/VBScript_DOC2PDF" target="_blank" rel="noopener">https://github.com/cxgreat2014/VBScript_DOC2PDF</a> <a href="https://github.com/JasonKhew96/Docs2Pdf" target="_blank" rel="noopener">https://github.com/JasonKhew96/Docs2Pdf</a></p>
<h3 id="wkhtmltopdf"><a href="#wkhtmltopdf" class="headerlink" title="wkhtmltopdf"></a>wkhtmltopdf</h3><p>这是一个非常好用的HTML转PDF的命令行工具，之前的文章<a href="https://mp.weixin.qq.com/s/ly4KnTCvBLlyqFBbBleFCQ" target="_blank" rel="noopener">Python 抓取知识星球内容生成词云和 PDF</a> 就是用的这个。<a href="https://wkhtmltopdf.org/downloads.html" target="_blank" rel="noopener">https://wkhtmltopdf.org/downloads.html</a><br>命令行执行 <code>wkhtmltopdf http://google.com google.pdf</code>就能将Google的网页生成PDF<br>python 有基于wkhtmltopdf的模块pdfkit，很方便在程序中转换HTML为PDF。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt;&gt;&gt; <span class="keyword">import</span> pdfkit</span><br><span class="line">&gt;&gt;&gt; config=pdfkit.configuration(wkhtmltopdf=r<span class="string">'d:\wkhtmltopdf\bin\wkhtmltopdf.exe'</span>)</span><br><span class="line"></span><br><span class="line">&gt;&gt;&gt; pdfkit.from_url(<span class="string">'http://qq.com'</span>,<span class="string">'qq.pdf'</span>,configuration=config)</span><br><span class="line">Loading pages (<span class="number">1</span>/<span class="number">6</span>)</span><br><span class="line">QFont::setPixelSize: Pixel size &lt;= <span class="number">0</span> (<span class="number">0</span>)                     ] <span class="number">43</span>%</span><br><span class="line">Counting pages (<span class="number">2</span>/<span class="number">6</span>)</span><br><span class="line">QFont::setPixelSize: Pixel size &lt;= <span class="number">0</span> (<span class="number">0</span>)=====================] <span class="built_in">Object</span> <span class="number">1</span> <span class="keyword">of</span> <span class="number">1</span></span><br><span class="line">Resolving links (<span class="number">4</span>/<span class="number">6</span>)</span><br><span class="line">Loading headers and footers (<span class="number">5</span>/<span class="number">6</span>)</span><br><span class="line">Printing pages (<span class="number">6</span>/<span class="number">6</span>)</span><br><span class="line">Done</span><br><span class="line">Warning: Received createRequest signal on a disposed ResourceObject<span class="string">'s NetworkAccessManager. This might be an indication of an iframe taking too long to load.</span></span><br><span class="line"><span class="string">Warning: Received createRequest signal on a disposed ResourceObject'</span>s NetworkAccessManager. This might be an indication <span class="keyword">of</span> an iframe taking too long to load.</span><br><span class="line">Warning: Received createRequest signal on a disposed ResourceObject<span class="string">'s NetworkAccessManager. This might be an indication of an iframe taking too long to load.</span></span><br><span class="line"><span class="string">True</span></span><br></pre></td></tr></table></figure></p>
<pre><code>如果文章对你有所帮助，还望不吝在看分享，感谢。
</code></pre><h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>PDF水印清理专家 <a href="http://www.liyusoft.com/pdfwr" target="_blank" rel="noopener">http://www.liyusoft.com/pdfwr</a></p>
<p> 一款免费的线上PDF转换器<a href="https://www.pdfyeah.com/" target="_blank" rel="noopener">https://www.pdfyeah.com/</a><br>累死累活干不过做 PPT 的 <a href="https://github.com/ksky521/nodeppt" target="_blank" rel="noopener">https://github.com/ksky521/nodeppt</a> <a href="https://nodeppt.js.org/#slide=5" target="_blank" rel="noopener">https://nodeppt.js.org/#slide=5</a><br><a href="https://pdf2doc.com/zh/" target="_blank" rel="noopener">https://pdf2doc.com/zh/</a><br>吾爱破解论坛 爱盘 down.52pojie.cn 页面的源代码 <a href="https://github.com/ganlvtech/down_52pojie_cn" target="_blank" rel="noopener">https://github.com/ganlvtech/down_52pojie_cn</a><br><a href="https://github.com/icylogic/Office2PDF" target="_blank" rel="noopener">https://github.com/icylogic/Office2PDF</a><br>Laravel HTML 导出 PDF 方案 —– wkhtmltopdf Laravel-snappy<a href="https://laravel-china.org/articles/20450" target="_blank" rel="noopener">https://laravel-china.org/articles/20450</a><br><a href="http://www.pdfdo.com/" target="_blank" rel="noopener">http://www.pdfdo.com/</a><br><a href="http://www.pdfbao.com/" target="_blank" rel="noopener">http://www.pdfbao.com/</a><br><a href="https://pdf.io/tw/" target="_blank" rel="noopener">https://pdf.io/tw/</a><br> <a href="https://zhuanlan.zhihu.com/p/21538584" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/21538584</a><br>得力PDF转换器 <a href="http://www.pdf2word.cn/" target="_blank" rel="noopener">http://www.pdf2word.cn/</a><br> 十七款PDF在线处理转换器<a href="https://m.weibo.cn/status/4395383201418956" target="_blank" rel="noopener">https://m.weibo.cn/status/4395383201418956</a><br>初识wkhtmltopdf <a href="https://segmentfault.com/a/1190000018765575" target="_blank" rel="noopener">https://segmentfault.com/a/1190000018765575</a><br>将您的图片转换成多种图片格式。<br>JPG, PNG, GIF, BMP, TIFF, ICO, SVG和更多图片格式 <a href="https://jinaconvert.com/cn/" target="_blank" rel="noopener">https://jinaconvert.com/cn/</a><br>pdf 转 word 工具 <a href="https://www.pdfpai.com/" target="_blank" rel="noopener">https://www.pdfpai.com/</a><br><a href="https://www.aconvert.com/cn/pdf/" target="_blank" rel="noopener">https://www.aconvert.com/cn/pdf/</a><br><a href="http://edit.foxitcloud.cn/" target="_blank" rel="noopener">http://edit.foxitcloud.cn/</a><br>命令行就可以把网页保存成 PDF 文件 <a href="https://github.com/danburzo/percollate" target="_blank" rel="noopener">https://github.com/danburzo/percollate</a><br><a href="https://www.extractpdf.com/一个可以将" target="_blank" rel="noopener">https://www.extractpdf.com/一个可以将</a> pdf 中的图片全部提取出来并打包下载的一个工具，还可以看到文档中纯文字部分<br>一个能完美的将网页导出到PDF的在线服务，可使用其提供的API，在你的在线简历页面添加一个PDF导出按钮。地址<a href="https://www.sejda.com/html-to-pdf" target="_blank" rel="noopener">https://www.sejda.com/html-to-pdf</a><br><a href="http://tools.bugscaner.com/webmaster/" target="_blank" rel="noopener">http://tools.bugscaner.com/webmaster/</a><br><a href="https://www.extractpdf.com/一个可以将" target="_blank" rel="noopener">https://www.extractpdf.com/一个可以将</a> pdf 中的图片全部提取出来并打包下载的一个工具，还可以看到文档中纯文字部分<br>一个能完美的将网页导出到PDF的在线服务，可使用其提供的API，在你的在线简历页面添加一个PDF导出按钮。地址<a href="https://www.sejda.com/html-to-pdf" target="_blank" rel="noopener">https://www.sejda.com/html-to-pdf</a><br>  <a href="https://github.com/Nihiue/ilovepdf-node" target="_blank" rel="noopener">https://github.com/Nihiue/ilovepdf-node</a> <a href="https://github.com/Nihiue/libreoffice-portal" target="_blank" rel="noopener">https://github.com/Nihiue/libreoffice-portal</a><br> pdf to ppt <a href="https://github.com/TomAnthony/pdf-to-powerpoint" target="_blank" rel="noopener">https://github.com/TomAnthony/pdf-to-powerpoint</a><br>需要安装 <a href="http://blog.alivate.com.au/poppler-windows/" target="_blank" rel="noopener">http://blog.alivate.com.au/poppler-windows/</a> 加入环境变量  pdftotext file.pdf - | grep string<br> <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">$ python convert.py wechat_article.pdf</span><br><span class="line"></span><br><span class="line">Converting file: wechat_article.pdf</span><br><span class="line"></span><br><span class="line">Starting conversion...</span><br><span class="line">...complete.</span><br><span class="line"></span><br><span class="line">Saving slide: <span class="number">0</span></span><br><span class="line"></span><br><span class="line">Saving file: wechat_article.pptx</span><br><span class="line">Conversion complete. :)</span><br><span class="line">$ pdfinfo.exe  wechat_article.pdf</span><br><span class="line">Title:</span><br><span class="line">Creator:        wkhtmltopdf <span class="number">0.12</span><span class="number">.5</span></span><br><span class="line">Producer:       Qt <span class="number">4.8</span><span class="number">.7</span></span><br><span class="line">CreationDate:   <span class="number">07</span>/<span class="number">01</span>/<span class="number">19</span> <span class="number">20</span>:<span class="number">22</span>:<span class="number">41</span> ▒й▒▒▒׼ʱ▒▒</span><br><span class="line">Tagged:         no</span><br><span class="line">UserProperties: no</span><br><span class="line">Suspects:       no</span><br><span class="line">Form:           none</span><br><span class="line">JavaScript:     no</span><br><span class="line">Pages:          <span class="number">5</span></span><br><span class="line">Encrypted:      no</span><br><span class="line">Page size:      <span class="number">595</span> x <span class="number">842</span> pts (A4)</span><br><span class="line">Page rot:       <span class="number">0</span></span><br><span class="line">File size:      <span class="number">117566</span> bytes</span><br><span class="line">Optimized:      no</span><br><span class="line">PDF version:    <span class="number">1.4</span></span><br><span class="line">https:<span class="comment">//github.com/ernestyao/PPT2PDF http://blog.51yip.com/other/1934.html</span></span><br><span class="line">https:<span class="comment">//wkhtmltopdf.org/downloads.html</span></span><br></pre></td></tr></table></figure></p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/_3AeNahwbs8c3UJ0is1t4A" target="_blank" rel="noopener">如何在电脑上登陆多个微信</a></p>
<p><a href="https://mp.weixin.qq.com/s/qyFvOgHf1mXwPKO0tQwUyg" target="_blank" rel="noopener">如何提取公积金 9 天到账</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/qNfuWjH54WHJtx4sEE5xwA" target="_blank" rel="noopener">10%+10% 不等于 0.2？</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/没有提取码怎么获取百度网盘资源？/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/没有提取码怎么获取百度网盘资源？/" itemprop="url">没有提取码怎么获取百度网盘资源？</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:26:26+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>之前已经写过<a href="https://mp.weixin.qq.com/s/H8VPSGt62-tblpgWkleQoQ" target="_blank" rel="noopener">那些你可能不知道的百度文库/网盘快速下载工具</a>，这次再来说说提取码，分享网盘资源默认是必须要设置提取码的，如果不想设置怎么办呢？<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a0193a8efb794094.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="无提取码"><a href="#无提取码" class="headerlink" title="无提取码"></a>无提取码</h3><p>加上一段代码就可以不需要提取码了，按F12在控制台输入以下代码：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">".share-method-line"</span>).parent().append(<span class="string">'&lt;div class="share-method-line"&gt;&lt;input type="radio" id="share-method-public" name="share-method" value="public" checked=""&gt;&lt;span class="icon radio-icon icon-radio-non"&gt;&lt;/span&gt;&lt;label for="share-method-public"&gt;&lt;b&gt;公开分享&lt;/b&gt;&lt;span&gt;任何人访问链接即可查看，下载！&lt;/span&gt;  来自&lt;a href="http://mp.weixin.qq.com/mp/homepage?__biz=MzIyMjg2ODExMA==&amp;hid=1&amp;sn=e7478e21fb95dd2d2b39b7d00c344da8&amp;scene=18#wechat_redirect"&gt;苏生不惑&lt;/a&gt;&lt;/label&gt;&lt;/div&gt;'</span>)</span><br></pre></td></tr></table></figure></p>
<p>这样就可以看到公开分享了，直接生成链接<a href="https://pan.baidu.com/s/12gIg-IN18uOUferhFs6-2A，不需要提取码就能打开。" target="_blank" rel="noopener">https://pan.baidu.com/s/12gIg-IN18uOUferhFs6-2A，不需要提取码就能打开。</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-b8b54b163531a38c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>当然大多数人不知道这个，所以分享的资源都有提取码，有时候在网上找电影，有人发了个网盘链接，但是没有给提取码，要加微信付费来获取提取码，真的很不爽，不知道提取码怎么能获取到网盘资源呢？下面分享几个工具。</p>
<h3 id="爱搜资源助手"><a href="#爱搜资源助手" class="headerlink" title="爱搜资源助手"></a>爱搜资源助手</h3><p>这个一个Chrome扩展，关于Chrome扩展之前已经写过<br><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a><br><a href="https://mp.weixin.qq.com/s/iluJYFYgT8bpMhrsxf0b5A" target="_blank" rel="noopener">Chrome 浏览器扩展神器暴力猴</a><br>网站 <a href="https://www.aisouziyuan.com/,安装完后的效果：" target="_blank" rel="noopener">https://www.aisouziyuan.com/,安装完后的效果：</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-3ed7b4d1fe473648.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>比如<a href="https://pan.baidu.com/s/1QcxFPwF7WxkI4eD6c-PFBw" target="_blank" rel="noopener">https://pan.baidu.com/s/1QcxFPwF7WxkI4eD6c-PFBw</a> 这个网盘链接有提取码，不知道的话没法进去。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d1045389be084ef0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装扩展后会自动填写提取码进入。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-4f7d575a3368e522.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>当然这个不是百分之百能获取到提取码的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-cb37dd941163acd7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>而且这个还支持微云的分享密码。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3176b7220da96e02.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="油猴脚本"><a href="#油猴脚本" class="headerlink" title="油猴脚本"></a>油猴脚本</h3><p>百度网盘超级助手<a href="https://greasyfork.org/zh-CN/scripts/389566" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/389566</a><br>这个油猴脚本支持提取码自动填写、pandownload资源全速下载、链接状态自动判断。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-818be45ff5f1c8ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装后打开网盘链接会自动搜索填写提取码。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-cb13a44243a6b3e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="云盘万能钥匙"><a href="#云盘万能钥匙" class="headerlink" title="云盘万能钥匙"></a>云盘万能钥匙</h3><p>这也是个Chrome扩展，网站 <a href="http://ypsuperkey.meek.com.cn/" target="_blank" rel="noopener">http://ypsuperkey.meek.com.cn/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-f25b6f850900d671.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>效果和上面的差不多</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-97002b996a94b0e4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-0f790bcec444a0e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果你不想安装扩展，有人还基于云盘万能钥匙API的开发了在线查询工具 <a href="https://pnote.net/pan/" target="_blank" rel="noopener">https://pnote.net/pan/</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-43a21d00ce7d0d31.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p> 当然还有人开发了桌面版软件<a href="https://pan.baidu.com/s/1LZx_7bvTwxA5U8i6ILlPfw" target="_blank" rel="noopener">https://pan.baidu.com/s/1LZx_7bvTwxA5U8i6ILlPfw</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1e099ecff529c6ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p><a href="https://node.pnote.net/public/pan?url=https://pan.baidu.com/s/1xLIwfqZsbV3jWP07neU4HA" target="_blank" rel="noopener">网盘接口</a><br>查询百度网盘提取密码<a href="https://github.com/wu-dada/baidupankey" target="_blank" rel="noopener">https://github.com/wu-dada/baidupankey</a><br>百度云盘万能钥匙<a href="http://tools.bugscaner.com/baiduyunpassword/" target="_blank" rel="noopener">http://tools.bugscaner.com/baiduyunpassword/</a><br>百度网盘提取码在线查询<a href="https://pan.09l.me/pwd" target="_blank" rel="noopener">https://pan.09l.me/pwd</a><br>万能云精灵<a href="https://bbs.pediy.com/thread-226701.htm" target="_blank" rel="noopener">https://bbs.pediy.com/thread-226701.htm</a><br><a href="https://hao.su/1717/" target="_blank" rel="noopener">https://hao.su/1717/</a><br>网盘万能钥匙<a href="https://go2think.com/wp-key-auto-fill/" target="_blank" rel="noopener">https://go2think.com/wp-key-auto-fill/</a><br> <a href="http://www.xia1ge.com/bdtqmsb.html" target="_blank" rel="noopener">百度网盘提取码自动识别</a></p>
<p><a href="https://pan.baiduwp.com/s/1PVrRkX1K3mQMXnnTEgJGxQ?pwd=ju2b" target="_blank" rel="noopener">https://pan.baiduwp.com/s/1PVrRkX1K3mQMXnnTEgJGxQ?pwd=ju2b</a><br><a href="https://www.xiaokesoso.com/s/search?q=%E5%B2%81%E6%9C%88%E7%A5%9E%E5%81%B7&amp;currentPage=1" target="_blank" rel="noopener">网盘搜索</a><br>百度网盘直链下载助手<a href="https://github.com/syhyz1990/baiduyun/" target="_blank" rel="noopener">https://github.com/syhyz1990/baiduyun/</a><br>谷歌助手 <a href="https://www.macdown.com/mac/2441.html" target="_blank" rel="noopener">https://www.macdown.com/mac/2441.html</a><br><a href="https://bbs.leyuz.net/t/100918" target="_blank" rel="noopener">百度网盘提取码查询的软件</a><br><a href="https://www.tenlonstudio.com/4435.html" target="_blank" rel="noopener">https://www.tenlonstudio.com/4435.html</a><br>是时候舍弃百度网盘客户端了，拥抱aria2免登陆不限速下载百度云资源了 <a href="https://www.jianshu.com/p/0981af1413cf" target="_blank" rel="noopener">https://www.jianshu.com/p/0981af1413cf</a><br>满速下载百度云神器<a href="https://www.jianshu.com/p/97f314af6d79" target="_blank" rel="noopener">https://www.jianshu.com/p/97f314af6d79</a><br>百度云提取码破解<a href="https://greasyfork.org/zh-CN/scripts/380664" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/380664</a><br>百度云盘提取码小工具<a href="https://www.yudouyudou.com/ziyuanxiazai/gongjuchajian/1555.html" target="_blank" rel="noopener">https://www.yudouyudou.com/ziyuanxiazai/gongjuchajian/1555.html</a><br> 查询百度网盘提取码<a href="https://www.52pojie.cn/thread-920211-1-1.html" target="_blank" rel="noopener">https://www.52pojie.cn/thread-920211-1-1.html</a><br>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/l2bQJk1qjb6IzroODBpoOg" target="_blank" rel="noopener">想看的公众号文章被删了怎么办？</a></p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/hbzmqep2JMICL6WogE9TCQ" target="_blank" rel="noopener">有意思的举牌告白小人</a></p>
<p><a href="https://mp.weixin.qq.com/s/_3AeNahwbs8c3UJ0is1t4A" target="_blank" rel="noopener">如何在电脑上登陆多个微信</a></p>
<p><a href="https://mp.weixin.qq.com/s/qyFvOgHf1mXwPKO0tQwUyg" target="_blank" rel="noopener">如何提取公积金 9 天到账</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/sng3uK9Nge1OD2gc5DDuZg" target="_blank" rel="noopener">那些你可能用得上的简历写作工具</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/怕被发垃圾邮件？用临时邮箱来注册账号/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/怕被发垃圾邮件？用临时邮箱来注册账号/" itemprop="url">怕被发垃圾邮件？用临时邮箱来注册账号</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:25:44+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  548 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  2 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>注册网站一般都需要邮箱，但有时候不想用自己的邮箱来注册，有些网站总给你发垃圾广告，这时可以用临时邮箱来注册。</p>
<p>临时邮箱也被称为一次性邮箱和匿名邮箱，就是提供一个简易的临时邮箱服务，不需要注册，打开网页即可使用，但临时邮箱时效性很短，通常只有10分钟，一小时或者一天，所以不能作为一个长期固定的邮箱来使用。</p>
<h3 id="十分钟邮箱"><a href="#十分钟邮箱" class="headerlink" title="十分钟邮箱"></a>十分钟邮箱</h3><p><a href="https://bccto.me/" target="_blank" rel="noopener">https://bccto.me/</a>  生成一个自定义邮箱地址 <a href="mailto:susheng@bccto.me" target="_blank" rel="noopener">susheng@bccto.me</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-dee47cedf254f8bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>很快收到一封邮件，可以查看到邮件内容<br><img src="https://upload-images.jianshu.io/upload_images/17817191-87759b7c6747e3d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="三十分钟邮箱"><a href="#三十分钟邮箱" class="headerlink" title="三十分钟邮箱"></a>三十分钟邮箱</h3><p><a href="https://shorttimemail.com/zh-Hans" target="_blank" rel="noopener">https://shorttimemail.com/zh-Hans</a> 生成一个临时邮箱 <a href="mailto:k8sf27e_j@shorttimemail.com" target="_blank" rel="noopener">k8sf27e_j@shorttimemail.com</a> </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-564899a2f1f214a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-05590edc1b5bb541.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="一小时邮箱"><a href="#一小时邮箱" class="headerlink" title="一小时邮箱"></a>一小时邮箱</h3><p><a href="https://www.moakt.com/zh" target="_blank" rel="noopener">https://www.moakt.com/zh</a> 生成一个自定义邮箱地址<a href="mailto:susheng@disbox.net" target="_blank" rel="noopener">susheng@disbox.net</a> 有效期为一个小时，自己发送邮箱测试下效果。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-62fa5038c3c6a98c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-4d0a7e767c93836b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>过期前还能延时<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3d3772ab3812a98c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="24小时邮箱"><a href="#24小时邮箱" class="headerlink" title="24小时邮箱"></a>24小时邮箱</h3><p><a href="http://24mail.chacuo.net/" target="_blank" rel="noopener">http://24mail.chacuo.net/</a> 这个网站会临时给你生成个邮箱地址，你也可以自定义，比如这个 <a href="mailto:zjupef35610@chacuo.net" target="_blank" rel="noopener">zjupef35610@chacuo.net</a> ，24小时后失效，网站给这个邮箱发的邮件直接可以在下面显示出来。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-604617076789725c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-29de33c926ec87b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果网站还需要手机号注册，也怕被发垃圾短信，同样有临时手机号来接受短信，比如<a href="https://www.pdflibr.com/SMSContent/1" target="_blank" rel="noopener">https://www.pdflibr.com/SMSContent/1</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-20f64a1830bdf1cb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p><a href="https://temp-mail.org/zh/" target="_blank" rel="noopener">https://temp-mail.org/zh/</a><br><a href="https://9em.org/" target="_blank" rel="noopener">https://9em.org/</a><br>短信<a href="http://www.z-sms.com/" target="_blank" rel="noopener">http://www.z-sms.com/</a><br>高效搜罗导航<a href="http://www.gaoxiaosouluo.cn/" target="_blank" rel="noopener">http://www.gaoxiaosouluo.cn/</a><br> 代接受验证码的网站，<br><a href="http://www.smszk.com/" target="_blank" rel="noopener">http://www.smszk.com/</a> 如果不想用自己的手机接受验证码的话，可以用这个可以暂时解决短信收发的问题<br>代收短信 <a href="http://www.pdflibr.com/" target="_blank" rel="noopener">www.pdflibr.com/</a><br><a href="https://sms.bilulanlv.com/message/3322077483.html" target="_blank" rel="noopener">https://sms.bilulanlv.com/message/3322077483.html</a><br>在线收到短信 <a href="https://www.becmd.com/" target="_blank" rel="noopener">https://www.becmd.com/</a><br> <a href="https://www.cnwml.com/" target="_blank" rel="noopener">https://www.cnwml.com/</a><br>免费ssr <a href="https://www.attackmen.com/" target="_blank" rel="noopener">https://www.attackmen.com/</a> </p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/qNfuWjH54WHJtx4sEE5xwA" target="_blank" rel="noopener">10%+10% 不等于 0.2？</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/那些我常用的-Chrome-扩展/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/那些我常用的-Chrome-扩展/" itemprop="url">那些我常用的 Chrome 扩展</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:24:50+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Chrome仍然是目前最好的浏览器，每天用Chrome 必然少不了使用扩展来增强浏览器的功能，这里整理下我常用的Chrome 扩展。</p>
<h3 id="油猴"><a href="#油猴" class="headerlink" title="油猴"></a>油猴</h3><p>这个简直神器，所以第一个推荐 <a href="https://www.tampermonkey.net/" target="_blank" rel="noopener">https://www.tampermonkey.net/</a> 下载后在<a href="https://greasyfork.org/zh-CN" target="_blank" rel="noopener">https://greasyfork.org/zh-CN</a> 这里安装对应的脚本。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-6adf0aadf65e6fbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>常用的脚本比如百度网盘直链下载<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b7cb5eda1a10d0f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>全网VIP视频免费观看</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-b2f94d4075308365.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>之前已经写过<br> <a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a><br><a href="https://mp.weixin.qq.com/s/iluJYFYgT8bpMhrsxf0b5A" target="_blank" rel="noopener">Chrome 浏览器扩展神器暴力猴</a><br>下载地址 <a href="https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo</a></p>
<h3 id="取字"><a href="#取字" class="headerlink" title="取字"></a>取字</h3><p>之前写过ocr <a href="https://mp.weixin.qq.com/s/CHb3gOMfGjwNjaznbv0R4g" target="_blank" rel="noopener">那些你可能不知道的 ocr 图片文字识别工具</a>，虽然有桌面版工具天若ocr，但在浏览器里还是用<code>取字</code>这个扩展方便<a href="http://willingstudio.com/#install" target="_blank" rel="noopener">http://willingstudio.com/#install</a>   ，它具有通识化场景的 OCR 识别功能浏览器插件，快速框选，可精确识别图片或者视频中的文本。</p>
<p>它提供本地安装和Chrome应用商店安装<a href="https://chrome.google.com/webstore/detail/jmonhcfndjifnfldnaknlpgpfjlgpiig?from=http://willingstudio.com" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/jmonhcfndjifnfldnaknlpgpfjlgpiig?from=http://willingstudio.com</a> 安装方法上面也有，上不了Google推荐下面的方法。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e026322ce645c90c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p> 使用效果如图：<br><img src="https://upload-images.jianshu.io/upload_images/17817191-15a0fc4ec4265e66.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-7ba1a80601a553fc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="WEB前端助手"><a href="#WEB前端助手" class="headerlink" title="WEB前端助手"></a>WEB前端助手</h3><p>这个扩展包含多个独立小应用，比如：Json工具、代码美化、代码压缩、二维码、Postman、markdown、网页油猴、便签笔记、信息加密与解密、随机密码生成、Crontab等等！<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d7b8292e30dc79cc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>扩展地址 <a href="https://chrome.google.com/webstore/detail/web%E5%89%8D%E7%AB%AF%E5%8A%A9%E6%89%8Bfehelper/pkgccpejnmalmdinmhkkfafefagiiiad?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/web%E5%89%8D%E7%AB%AF%E5%8A%A9%E6%89%8Bfehelper/pkgccpejnmalmdinmhkkfafefagiiiad?hl=zh-CN</a></p>
<h3 id="listen1"><a href="#listen1" class="headerlink" title="listen1"></a>listen1</h3><p>Listen 1可以搜索和播放来自网易云音乐，虾米，QQ音乐，酷狗音乐，酷我音乐网站的歌曲，让你的曲库更全面，不用一个个找了。<a href="https://listen1.github.io/listen1/" target="_blank" rel="noopener">https://listen1.github.io/listen1/</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-eef4692e567c2a2f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>之前也写过 <a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<h3 id="极简-Json-格式化"><a href="#极简-Json-格式化" class="headerlink" title="极简 Json 格式化"></a>极简 Json 格式化</h3><p>这个用来看json格式的接口最方便了，由<a href="https://atool.vip/#/" target="_blank" rel="noopener">https://atool.vip/#/</a>提供。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f325d2e123ce8112.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址 <a href="https://chrome.google.com/webstore/detail/%E6%9E%81%E7%AE%80-json-%E6%A0%BC%E5%BC%8F%E5%8C%96/fhlnfdmpnhhakjljpllkigcegcejpoec?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/%E6%9E%81%E7%AE%80-json-%E6%A0%BC%E5%BC%8F%E5%8C%96/fhlnfdmpnhhakjljpllkigcegcejpoec?hl=zh-CN</a></p>
<h3 id="百度网盘助手"><a href="#百度网盘助手" class="headerlink" title="百度网盘助手"></a>百度网盘助手</h3><p>用来下载百度网盘的工具 增加高速下载按钮。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-23ca4429842e815a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址  <a href="https://github.com/high-speed-downloader/high-speed-downloader" target="_blank" rel="noopener">https://github.com/high-speed-downloader/high-speed-downloader</a></p>
<h3 id="图片助手"><a href="#图片助手" class="headerlink" title="图片助手"></a>图片助手</h3><p>一款Chrome浏览器中用于嗅探、分析网页图片、图片筛选、下载等功能及收藏、检索、分享等在线服务的扩展程序，无论图片是使用flash载入还是动态载入的，扩展都能很好地应对，真正做到所见即所得 <a href="http://www.pullywood.com/ImageAssistant/" target="_blank" rel="noopener">http://www.pullywood.com/ImageAssistant/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-4f4c94288819118a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址<a href="https://chrome.google.com/webstore/detail/imageassistant-batch-imag/dbjbempljhcmhlfpfacalomonjpalpko" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/imageassistant-batch-imag/dbjbempljhcmhlfpfacalomonjpalpko</a></p>
<h3 id="微博图床"><a href="#微博图床" class="headerlink" title="微博图床"></a>微博图床</h3><p>一个上传图片到微博并生成外链的 Chrome 浏览器扩展<a href="https://github.com/Semibold/Weibo-Picture-Store" target="_blank" rel="noopener">https://github.com/Semibold/Weibo-Picture-Store</a>，支持同步到微相册 ，需要浏览器登录微博。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-dd79a0d9e1c89cf7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址 <a href="https://chrome.google.com/webstore/detail/pinjkilghdfhnkibhcangnpmcpdpmehk" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/pinjkilghdfhnkibhcangnpmcpdpmehk</a></p>
<h3 id="谷歌访问助手"><a href="#谷歌访问助手" class="headerlink" title="谷歌访问助手"></a>谷歌访问助手</h3><p>这个上谷歌必备<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e0c8dc4074b512e4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址<a href="https://github.com/haotian-wang/google-access-helper/archive/master.zip" target="_blank" rel="noopener">https://github.com/haotian-wang/google-access-helper/archive/master.zip</a> 如果下载不了公众号回复 <code>谷歌</code> 获取</p>
<h3 id="爱搜资源云盘助手"><a href="#爱搜资源云盘助手" class="headerlink" title="爱搜资源云盘助手"></a>爱搜资源云盘助手</h3><p>之前写过文章 <a href="https://mp.weixin.qq.com/s/MUIPj4OgSxAeRl5Hk-2tuw" target="_blank" rel="noopener">没有提取码怎么获取百度网盘资源？</a>，不用自己输入提取码。<a href="https://www.aisouziyuan.com/" target="_blank" rel="noopener">https://www.aisouziyuan.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-9c50d75dd07d538a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址 <a href="https://chrome.google.com/webstore/detail/%E7%88%B1%E6%90%9C%E8%B5%84%E6%BA%90%E4%BA%91%E7%9B%98%E5%8A%A9%E6%89%8B-%E7%A8%B3%E5%AE%9A%E7%89%88/mbklgpngoohbbagagdfoccaclpdhgihd?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/%E7%88%B1%E6%90%9C%E8%B5%84%E6%BA%90%E4%BA%91%E7%9B%98%E5%8A%A9%E6%89%8B-%E7%A8%B3%E5%AE%9A%E7%89%88/mbklgpngoohbbagagdfoccaclpdhgihd?hl=zh-CN</a></p>
<h3 id="壹伴"><a href="#壹伴" class="headerlink" title="壹伴"></a>壹伴</h3><p>经常使用公众号推荐这个工具，数据统计，点赞率和留言率都显示出来。<a href="https://yiban.io/" target="_blank" rel="noopener">https://yiban.io/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-4bb00580415bb978.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址 <a href="https://chrome.google.com/webstore/detail/%E5%A3%B9%E4%BC%B4-%C2%B7-%E5%B0%8F%E6%8F%92%E4%BB%B6/ibefaeehajgcpooopoegkifhgecigeeg" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/%E5%A3%B9%E4%BC%B4-%C2%B7-%E5%B0%8F%E6%8F%92%E4%BB%B6/ibefaeehajgcpooopoegkifhgecigeeg</a></p>
<h3 id="一键视频下载器"><a href="#一键视频下载器" class="headerlink" title="一键视频下载器"></a>一键视频下载器</h3><p>比如微博上的视频，点击按钮就能显示当前可以下载的视频，直接点击下载到本地。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-de4d190cdfd3d06f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>下载地址 <a href="https://chrome.google.com/webstore/detail/one-click-video-downloade/bhepgcoaibmmehlmckhlmbdgcemhidcg" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/one-click-video-downloade/bhepgcoaibmmehlmckhlmbdgcemhidcg</a></p>
<h3 id="翻译"><a href="#翻译" class="headerlink" title="翻译"></a>翻译</h3><p>co-trans-ext 是一个集搜狗翻译、百度翻译、谷歌翻译、有道翻译、金山词霸于一体的翻译扩展。各平台可随时切换，取长补短，更适合于阅读各领域的文档。不止于翻译，解析详细，更利于对各门语言的深入学习与理解。支持划词翻译和网页翻译。<br>下载后将crx后缀改为zip，然后拖到扩展中，除了翻译还提供发音，非常好用。<br> <img src="https://upload-images.jianshu.io/upload_images/17817191-62f9c2fe40fa8f5d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址：<a href="https://github.com/Coande/co-trans-ext" target="_blank" rel="noopener">https://github.com/Coande/co-trans-ext</a></p>
<h3 id="截图"><a href="#截图" class="headerlink" title="截图"></a>截图</h3><p>它满足截图所有的需求，截取可见网页，选择区域，整个网页，录屏，捕获整个页面或任何部分，矩形，圆形，箭头，线条和文字，模糊敏感信息，一键上传分享注释。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7a49328c5baf176b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-4dcae7ed5ab8b479.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址<a href="https://chrome.google.com/webstore/detail/awesome-screenshot-screen/nlipoenfbbikpbjkfpfillcgkoblgpmj" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/awesome-screenshot-screen/nlipoenfbbikpbjkfpfillcgkoblgpmj</a></p>
<h3 id="聊天"><a href="#聊天" class="headerlink" title="聊天"></a>聊天</h3><p>和浏览相同网页的人实时聊天，发弹幕！<a href="http://yiyechat.com/" target="_blank" rel="noopener">http://yiyechat.com/</a><br>该扩展可以在任意网页增加一个简洁的聊天盒，让您可以和浏览当前网站的其他用户聊天！</p>
<p>这是百度页面的聊天<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a1f8b3bd1897ec60.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下载地址 <a href="https://chrome.google.com/webstore/detail/same-page/bldcellajihanglphncgjmceklbibjkk" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/same-page/bldcellajihanglphncgjmceklbibjkk</a></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>用Chrome学编程(如何用Chrome优雅装B) <a href="https://github.com/zhaoolee/ProgrammingWithChrome" target="_blank" rel="noopener">https://github.com/zhaoolee/ProgrammingWithChrome</a><br>Chrome插件英雄榜 <a href="https://zhaoolee.gitbooks.io/chrome/content/" target="_blank" rel="noopener">https://zhaoolee.gitbooks.io/chrome/content/</a><br>那些离不开的 Chrome 扩展插件<a href="https://michael728.github.io/2015/11/26/tools-chrome-extentions/" target="_blank" rel="noopener">https://michael728.github.io/2015/11/26/tools-chrome-extentions/</a></p>
<p>你平常用了哪些不错的扩展，也欢迎评论给我推荐下。</p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/_3AeNahwbs8c3UJ0is1t4A" target="_blank" rel="noopener">如何在电脑上登陆多个微信</a></p>
<p><a href="https://mp.weixin.qq.com/s/qyFvOgHf1mXwPKO0tQwUyg" target="_blank" rel="noopener">如何提取公积金 9 天到账</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/qNfuWjH54WHJtx4sEE5xwA" target="_blank" rel="noopener">10%+10% 不等于 0.2？</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/那些你可能不知道的小众搜索引擎/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/那些你可能不知道的小众搜索引擎/" itemprop="url">那些你可能不知道的小众搜索引擎</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:24:05+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  477 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>国内大多数人在使用百度，但有些搜索结果广告多，而且有时候搜不到满意的结果，谷歌又访问不了，不过你可以试试下面这些小众的搜索引擎。</p>
<h3 id="dogedoge"><a href="#dogedoge" class="headerlink" title="dogedoge"></a>dogedoge</h3><p>一个不追踪隐私的搜索引擎<a href="https://www.dogedoge.com/" target="_blank" rel="noopener">https://www.dogedoge.com/</a> 页面干净无广告。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-55834a0ba01a2b5c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-b771c09596494c70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="mijisou"><a href="#mijisou" class="headerlink" title="mijisou"></a>mijisou</h3><p>秘迹搜索也是一个 不追踪你的搜索引擎 <a href="https://mijisou.com/" target="_blank" rel="noopener">https://mijisou.com/</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-954796fc9824ee62.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="goobe"><a href="#goobe" class="headerlink" title="goobe"></a>goobe</h3><p>一个好用的程序员搜索<a href="https://goobe.io/" target="_blank" rel="noopener">https://goobe.io/</a>  对比下百度搜索结果<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e28cc8b67a298f64.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2472f8a0718be102.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="mezw"><a href="#mezw" class="headerlink" title="mezw"></a>mezw</h3><p><a href="https://so.mezw.com/" target="_blank" rel="noopener">https://so.mezw.com/</a> MEZW搜索是一家聚合搜索引擎网站，致力于为用户提供准确、干净的网页内容搜索服务，搜索结果来自海内外不同内容渠道的聚合。<br> <img src="https://upload-images.jianshu.io/upload_images/17817191-a39ae70ef6b66375.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="Lookao"><a href="#Lookao" class="headerlink" title="Lookao"></a>Lookao</h3><p><a href="https://lookao.com/" target="_blank" rel="noopener">https://lookao.com/</a>  Lookao 是一款轻量简洁的搜索引擎，它不会收集你的隐私、追踪你的上网行为。也不会根据你的历史记录来干预搜索排名，搜索结果千人一面，内容更加纯粹。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-95a34f146eabb49f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="中国搜"><a href="#中国搜" class="headerlink" title="中国搜"></a>中国搜</h3><p><a href="http://www.chinaso.com" target="_blank" rel="noopener">http://www.chinaso.com</a> ，第一条不是广告。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-08071220aedc7c89.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="聚合搜索"><a href="#聚合搜索" class="headerlink" title="聚合搜索"></a>聚合搜索</h3><p><a href="https://gobaidugle.com/" target="_blank" rel="noopener">https://gobaidugle.com/</a> 可以自由切换不同的搜索引擎，比如百度谷歌搜狗淘宝京东等。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5cd49f64439e3024.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>虽然上面的是不同的搜索引擎，但搜索技巧是相通的，推荐看之前整理的文章 <a href="https://mp.weixin.qq.com/s/-5tZWfeWWa_E8jRCH0T_Cw" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p>还有萌搜 <a href="https://mengso.com" target="_blank" rel="noopener">https://mengso.com</a> 目前不可访问。</p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/hbzmqep2JMICL6WogE9TCQ" target="_blank" rel="noopener">有意思的举牌告白小人</a></p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/_3AeNahwbs8c3UJ0is1t4A" target="_blank" rel="noopener">如何在电脑上登陆多个微信</a></p>
<p><a href="https://mp.weixin.qq.com/s/qyFvOgHf1mXwPKO0tQwUyg" target="_blank" rel="noopener">如何提取公积金 9 天到账</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/qNfuWjH54WHJtx4sEE5xwA" target="_blank" rel="noopener">10%+10% 不等于 0.2？</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/10-10-不等于-0-2？/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/10-10-不等于-0-2？/" itemprop="url">10%+10% 不等于 0.2？</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:22:14+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  502 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>看到这个标题，你可能会觉得震惊，怎么会不是0.2呢?</p>
<p>最近在知乎上看到这个有意思的问题<a href="https://www.zhihu.com/question/343963978" target="_blank" rel="noopener">https://www.zhihu.com/question/343963978</a><br>，为什么手机上的计算器计算 10%+10% 都错了，结果不是0.2，而是0.11。</p>
<p>第一感觉是不可思议，赶紧拿出我的华为手机（EMUI版本为9.1）测试了下，果然是0.11！<br><img src="https://upload-images.jianshu.io/upload_images/17817191-73c08239267c80b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>看看谷歌的计算器，0.2没错。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-8edcae05712bf3fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>但是搜索<code>计算器</code> 再计算的结果却是0.11，很奇怪。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-863f467eb61f366e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>然后在在线自动问答系统搜索引擎wolframalpha上看看<a href="https://www.wolframalpha.com/input/?i=10%25%2B10%25" target="_blank" rel="noopener">https://www.wolframalpha.com/input/?i=10%25%2B10%25</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-dd8788861fc35820.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>它给出了3种结果，有0.2和0.11 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5f4129ed1fdeb45f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>ps：<code>wolframalpha</code>这个网站计算数学很不错，比如黄金分割比0.618<br><img src="https://upload-images.jianshu.io/upload_images/17817191-1607024d1915ae17.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>再看看国家统计局的解释<br><a href="http://www.stats.gov.cn/tjzs/tjcd/200205/t20020523_25320.html" target="_blank" rel="noopener">http://www.stats.gov.cn/tjzs/tjcd/200205/t20020523_25320.html</a><br><a href="https://cn.v2ex.com/t/597205?p=1" target="_blank" rel="noopener">https://cn.v2ex.com/t/597205?p=1</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-0099f8eef073a704.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>搜索了下苹果和小米等手机都是如此。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-90020f8426177013.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>然而魅族手机却是个例外。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5265224ae0f486c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>魅族副总裁在微博上的解释是这样的 <a href="https://weibo.com/1444241363/I554TgDEs?" target="_blank" rel="noopener">https://weibo.com/1444241363/I554TgDEs?</a></p>
<blockquote>
<p>本质上并不是对或错的问题，我们只是考虑的更多，增加了人性化的算法判断。10%+10%=0.11 这个是国外的使用逻辑，而国内的算数逻辑是 10%+10%=0.2，所以我们针对不同地区的固件做了不同的算法判断。 </p>
</blockquote>
<blockquote>
<p> 算小费等特殊场景，很多国家餐厅吃饭给10-20%的小费，这时100+10%相当于100+100*10%，相当方便的一种人性化设计。</p>
</blockquote>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-53fad4198a0e3e79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>所以10%+10%是按照10%+（10% x 10%）这个逻辑得出0.11的结果，10+10%就是11。</p>
<p>只能说国内和国外使用习惯不同，中国人没有付小费的习惯，而且我们一般是用0.1+0.1算的，这应该算计算器的feature，不算bug。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8e845b47fe8eb3a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p> 看看你的手机计算器结果是0.2还是0.11？</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/16/想看的公众号文章被删了怎么办/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/16/想看的公众号文章被删了怎么办/" itemprop="url">想看的公众号文章被删了怎么办</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-16T20:20:50+08:00">
                2019-09-16
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.2k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>每个人都或多或少关注不少公众号，并且每人关注的公众号上限是1000，为什么我知道呢，因为我就关注到1000了，超过1000后再关注会提示这个。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3f8b59abeda07fb9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>关注这么多，我都会看吗？当然不会，哪有这么多时间，首先会看置顶的那些有意思的号，其他的主要来自朋友圈和在看里的文章，一般都是在微信里看文章，但如果上班时间摸鱼要看看公众号，拿手机肯定不方便（被发现更不方便），除了在微信里看公众号文章，其实还有很多网站抓取了公众号的文章，这样就可以直接在pc上看了。</p>
<p>而且很多文章因为某些原因就被删了，比如这样：<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a90fd38042b6a56d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-20b6986c48f53554.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>有了这些第三方网站，这样的文章你还能看到。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-d00b79ddd4a7f522.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-29da4eec13df56ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>下面推荐几个我常用的pc查看公众号文章网站/工具，以腾讯家的号 <code>微信派</code> 为例。</p>
<h3 id="微信pc客户端"><a href="#微信pc客户端" class="headerlink" title="微信pc客户端"></a>微信pc客户端</h3><p>这个不用说了，微信官方的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5237e30b01930d61.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="搜狗微信"><a href="#搜狗微信" class="headerlink" title="搜狗微信"></a>搜狗微信</h3><p>因为微信屏蔽了搜索引擎，<a href="https://mp.weixin.qq.com/robots.txt" target="_blank" rel="noopener">https://mp.weixin.qq.com/robots.txt</a> 这里可以看到<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">User-Agent: *</span><br><span class="line">Allow: <span class="regexp">/$</span></span><br><span class="line"><span class="regexp">Allow: /</span>debug/</span><br><span class="line">Allow: <span class="regexp">/qa/</span></span><br><span class="line">Allow: <span class="regexp">/wiki</span></span><br><span class="line"><span class="regexp">Allow: /</span>cgi-bin/loginpage</span><br><span class="line">Allow: <span class="regexp">/cgi-bin/</span>wx</span><br><span class="line">Disallow: <span class="regexp">/</span></span><br></pre></td></tr></table></figure></p>
<p>所以在谷歌百度上搜不到公众号的文章，但搜狗微信 <a href="https://weixin.sogou.com/" target="_blank" rel="noopener">https://weixin.sogou.com/</a> 是微信官方合作伙伴，所以这里有公众号文章的入口。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5b230713b6af824b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>之前每个号的主页可以看最近10条推送文章，但不知道为什么关闭了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5363a5b5a8f2b00b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>没关系，曲线救国，搜索里选择<code>账号内搜索</code>，时间选择最近一个月的，一样可以看到最近推送文章。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-9e623e17295f3088.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="今天看啥"><a href="#今天看啥" class="headerlink" title="今天看啥"></a>今天看啥</h3><p>网址 <a href="http://www.jintiankansha.me" target="_blank" rel="noopener">http://www.jintiankansha.me</a>  这个网站提供的公众号文章已经很多了，如果没有你想看的公众号可以自己来提交<a href="http://www.jintiankansha.me/about" target="_blank" rel="noopener">http://www.jintiankansha.me/about</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-f5468ec1a1ee2450.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>搜索 微信派 可以进入它的主页可以看到推送的文章<a href="http://www.jintiankansha.me/column/gREO9Ub5z6" target="_blank" rel="noopener">http://www.jintiankansha.me/column/gREO9Ub5z6</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-89c739ddebeaa441.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>这个网站是全文抓取的，比如这篇文章<a href="http://www.jintiankansha.me/t/lVkBWVkHq4" target="_blank" rel="noopener">http://www.jintiankansha.me/t/lVkBWVkHq4</a> 公众号原文是<a href="https://mp.weixin.qq.com/s/RgTkKhQYeaW61_b1p1rvuQ" target="_blank" rel="noopener">娱乐圈“三大程序员”现身，只为他们</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-49d65f21bf6c404d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>如果微信派删除了这篇文章，在公众号是没法看了，你还可以来这里看。</p>
<h3 id="瓦斯阅读"><a href="#瓦斯阅读" class="headerlink" title="瓦斯阅读"></a>瓦斯阅读</h3><p>网址 <a href="https://qnmlgb.tech/" target="_blank" rel="noopener">https://qnmlgb.tech/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-c925cfd67bb4e0bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>搜索 微信派 可以找到主页<a href="https://qnmlgb.tech/authors/5b644276244d4e5035e0b409" target="_blank" rel="noopener">https://qnmlgb.tech/authors/5b644276244d4e5035e0b409</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-2c417bf8a48ed35e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>这个网站查看文章还需要登录，不过注册也简单，但是它只是提供个入口，看文章还是跳转到微信的链接，所以如果被删了，就看不到了。</p>
<h3 id="二十次幂"><a href="#二十次幂" class="headerlink" title="二十次幂"></a>二十次幂</h3><p>网址<a href="https://www.ershicimi.com" target="_blank" rel="noopener">https://www.ershicimi.com</a> ，这也是一个微信公众号内容聚合网站。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ac448613e96b2dad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>搜索 微信派 进入主页<a href="https://www.ershicimi.com/a/121" target="_blank" rel="noopener">https://www.ershicimi.com/a/121</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-ca4a7ff67aecbe9d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>这个网站还提供数据分析，可以看到每篇文章阅读量和在看数。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-da09598899dbdd3a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>还能监控文章阅读数，如果阅读量增长（暴增）不正常可能是刷阅读了，详细内容看作者博客介绍<a href="https://foofish.net/ershicimi_monitor.html" target="_blank" rel="noopener">https://foofish.net/ershicimi_monitor.html</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-f8492671c8de6f98.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>有个不足的地方，它也是提供微信的链接，如果文章被删了，也就看不到了。</p>
<h3 id="传送门"><a href="#传送门" class="headerlink" title="传送门"></a>传送门</h3><p>网址<a href="https://chuansongme.com/" target="_blank" rel="noopener">https://chuansongme.com/</a> 这个网站存在好多年了，上面的文章也不少。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c40eb03008aaf087.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>搜索 微信派 进入主页<a href="https://chuansongme.com/account/wx-pai" target="_blank" rel="noopener">https://chuansongme.com/account/wx-pai</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-040eec9d34aadb61.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>它也是全文抓取的，不过数据有延时，<a href="https://mp.weixin.qq.com/s/RgTkKhQYeaW61_b1p1rvuQ" target="_blank" rel="noopener">娱乐圈“三大程序员”现身，只为他们</a> 这篇文章就还没收录。</p>
<p>好了，现在可以更安心的上班摸鱼了。</p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>新榜  <a href="https://data.newrank.cn/m/s.html?s=PigyPDI2KStL" target="_blank" rel="noopener">https://data.newrank.cn/m/s.html?s=PigyPDI2KStL</a><br><a href="https://wemp.app/posts/ecce54d7-84c2-44d8-a72e-8792c8060a2a" target="_blank" rel="noopener">https://wemp.app/posts/ecce54d7-84c2-44d8-a72e-8792c8060a2a</a><br><a href="https://www.ershicimi.com/a/6655" target="_blank" rel="noopener">https://www.ershicimi.com/a/6655</a><br><a href="https://mlog.club/user/616" target="_blank" rel="noopener">https://mlog.club/user/616</a><br><a href="https://qnmlgb.tech/authors/5b80eb36244d4e47d7a5c098?_lst=" target="_blank" rel="noopener">瓦斯阅读</a><br><a href="https://zhuanlan.zhihu.com/p/76684529" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/76684529</a><br>一个极简的微信公众号历史文章查阅网站. <a href="http://bsbx.vip/index.html?cid=3" target="_blank" rel="noopener">http://bsbx.vip/index.html?cid=3</a><br><a href="http://www.heijing.co/tag/mimeng7/page/9" target="_blank" rel="noopener">http://www.heijing.co/tag/mimeng7/page/9</a><br><a href="http://wenzhangyuan.com/qinggan/mimeng" target="_blank" rel="noopener">http://wenzhangyuan.com/qinggan/mimeng</a><br><a href="https://wemp.app/accounts/2577572b-07b7-44e7-b088-bada02266ef6" target="_blank" rel="noopener">https://wemp.app/accounts/2577572b-07b7-44e7-b088-bada02266ef6</a><br><a href="http://www.python88.com/" target="_blank" rel="noopener">http://www.python88.com/</a><br>我们还可以在「微信读书」中，以文集的方式订阅和阅读微信公众号里的文章。 <a href="https://weread.qq.com/" target="_blank" rel="noopener">https://weread.qq.com/</a><br> <a href="https://www.jianshu.com/p/5b151224c84c" target="_blank" rel="noopener">https://www.jianshu.com/p/5b151224c84c</a></p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/hbzmqep2JMICL6WogE9TCQ" target="_blank" rel="noopener">有意思的举牌告白小人</a></p>
<p><a href="https://mp.weixin.qq.com/s/_3AeNahwbs8c3UJ0is1t4A" target="_blank" rel="noopener">如何在电脑上登陆多个微信</a></p>
<p><a href="https://mp.weixin.qq.com/s/qyFvOgHf1mXwPKO0tQwUyg" target="_blank" rel="noopener">如何提取公积金 9 天到账</a></p>
<p><a href="https://mp.weixin.qq.com/s/1omFkK5PPyeJEzUTagj9qg" target="_blank" rel="noopener">免费在线听周杰伦歌曲</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/sng3uK9Nge1OD2gc5DDuZg" target="_blank" rel="noopener">那些你可能用得上的简历写作工具</a></p>
<p><a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a></p>
<p><a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-393b26173c148690.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/09/php-代码整理-续/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/09/php-代码整理-续/" itemprop="url">php 代码整理(续)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-09T19:37:31+08:00">
                2019-09-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  13.8k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  69 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="Excel-导入导出工具"><a href="#Excel-导入导出工具" class="headerlink" title="Excel 导入导出工具"></a>Excel 导入导出工具</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> phpoffice/phpspreadsheet</span><br><span class="line"><span class="built_in">require</span> <span class="string">'vendor/autoload.php'</span>;</span><br><span class="line"></span><br><span class="line">use PhpOffice\PhpSpreadsheet\Spreadsheet;</span><br><span class="line">use PhpOffice\PhpSpreadsheet\Writer\Xlsx;</span><br><span class="line"></span><br><span class="line">$spreadsheet = <span class="keyword">new</span> Spreadsheet();</span><br><span class="line">$sheet = $spreadsheet-&gt;getActiveSheet();</span><br><span class="line">$sheet-&gt;setCellValue(<span class="string">'A1'</span>, <span class="string">'Hello World !'</span>);</span><br><span class="line"></span><br><span class="line">$writer = <span class="keyword">new</span> Xlsx($spreadsheet);</span><br><span class="line">$writer-&gt;save(<span class="string">'hello world.xlsx'</span>);</span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/33677</span></span><br></pre></td></tr></table></figure>
<h3 id="FFmpeg-截取视频中多个图片-然后拼成一张图"><a href="#FFmpeg-截取视频中多个图片-然后拼成一张图" class="headerlink" title="FFmpeg 截取视频中多个图片,然后拼成一张图"></a>FFmpeg 截取视频中多个图片,然后拼成一张图</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">//获取文件路径</span></span><br><span class="line">   fwrite(STDOUT, <span class="string">"哪个视频文件:"</span>);</span><br><span class="line">   $video_path = trim(fgets(STDIN));</span><br><span class="line"></span><br><span class="line">   fwrite(STDOUT, <span class="string">"多少秒截取1张图:"</span>);</span><br><span class="line">   $s = trim(fgets(STDIN));</span><br><span class="line"></span><br><span class="line">   <span class="comment">//设置输出路径</span></span><br><span class="line">   fwrite(STDOUT, <span class="string">"输出到哪里:"</span>);</span><br><span class="line">   $export_path = trim(fgets(STDIN));</span><br><span class="line"></span><br><span class="line">   $command = system(<span class="string">'ffmpeg -y -i '</span>.$video_path.<span class="string">' -vf "fps=1/'</span>.$s.<span class="string">',scale=iw/4:-1,tile=2x2" -an '</span>.$export_path.<span class="string">'_%d.png'</span>); </span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/33066</span></span><br><span class="line">   <span class="comment">// fps = 1/2 每2秒截一张图,如果是每秒截一张 参数就是 fps=1</span></span><br><span class="line">   <span class="comment">// scale 截图大小,上面的代码是设置宽为原始的1/4大小,高度自动,也可以设置成固定值如:120:80</span></span><br><span class="line">   <span class="comment">// tile 网格化,自动将100张图合并成一张大图</span></span><br><span class="line">   截图会输出很多张大图，这不是我想要的，我只想从视频中提取 <span class="number">4</span> 张图片，然后拼接成一张大图怎么操作；</span><br><span class="line">    获得视频总时长然后除以 <span class="number">4</span> 就好了 (如果要 <span class="number">6</span> 张图就除以 <span class="number">6</span>)</span><br><span class="line">    代码如下:</span><br><span class="line">    $duration = system(<span class="string">'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i '</span>.$video_path.<span class="string">''</span>);</span><br><span class="line">    $s = $duration/<span class="number">4</span>;</span><br><span class="line">    $command = system(<span class="string">'ffmpeg -y -i '</span>.$videopath.<span class="string">' -vf "fps=1/'</span>.$s.<span class="string">',scale=iw/4:-1,tile=2x2" -an 1%d.png'</span>);</span><br></pre></td></tr></table></figure>
<h3 id="MySQL-事务最全详解"><a href="#MySQL-事务最全详解" class="headerlink" title="MySQL 事务最全详解"></a>MySQL 事务最全详解</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 我们先查看表中的数据,id为1的age字段是12</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select * <span class="keyword">from</span> user;</span><br><span class="line">+----+------+-----+</span><br><span class="line">| id | name | age |</span><br><span class="line">+----+------+-----+</span><br><span class="line">| <span class="number">1</span> | 张三 | <span class="number">12</span> |</span><br><span class="line">| <span class="number">2</span> | 李四 | <span class="number">15</span> |</span><br><span class="line">+----+------+-----+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.013</span>s</span><br><span class="line"><span class="comment">// 开启事务</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; begin;</span><br><span class="line">Query OK, <span class="number">0</span> rows affected</span><br><span class="line">Time: <span class="number">0.001</span>s</span><br><span class="line"><span class="comment">// 将id为1的age字段改为10</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; update user set age=<span class="number">10</span> where id=<span class="number">1</span>;</span><br><span class="line">Query OK, <span class="number">1</span> row affected</span><br><span class="line">Time: <span class="number">0.001</span>s</span><br><span class="line"><span class="comment">// 再次查询数据时,发现数据改为修改后的值</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select * <span class="keyword">from</span> user;</span><br><span class="line">+----+------+-----+</span><br><span class="line">| id | name | age |</span><br><span class="line">+----+------+-----+</span><br><span class="line">| <span class="number">1</span> | 张三 | <span class="number">10</span> |</span><br><span class="line">| <span class="number">2</span> | 李四 | <span class="number">15</span> |</span><br><span class="line">+----+------+-----+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.012</span>s</span><br><span class="line"><span class="comment">// 此时我们进行回滚操作</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; rollback;</span><br><span class="line">Query OK, <span class="number">0</span> rows affected</span><br><span class="line">Time: <span class="number">0.001</span>s</span><br><span class="line"><span class="comment">// 再次查询发现数据回到最初状态</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select * <span class="keyword">from</span> user;</span><br><span class="line">+----+------+-----+</span><br><span class="line">| id | name | age |</span><br><span class="line">+----+------+-----+</span><br><span class="line">| <span class="number">1</span> | 张三 | <span class="number">12</span> |</span><br><span class="line">| <span class="number">2</span> | 李四 | <span class="number">15</span> |</span><br><span class="line">+----+------+-----+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.019</span>s</span><br><span class="line"><span class="comment">// 我们再次对数据进行修改</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; update user set age=<span class="number">15</span> where id=<span class="number">1</span>;</span><br><span class="line">Query OK, <span class="number">1</span> row affected</span><br><span class="line">Time: <span class="number">0.001</span>s</span><br><span class="line"><span class="comment">// 此时将事务进行提交</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; commit;</span><br><span class="line">Query OK, <span class="number">0</span> rows affected</span><br><span class="line">Time: <span class="number">0.000</span>s</span><br><span class="line"><span class="comment">// 发现此时的数据变为我们最终提交的值</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select * <span class="keyword">from</span> user;</span><br><span class="line">+----+------+-----+</span><br><span class="line">| id | name | age |</span><br><span class="line">+----+------+-----+</span><br><span class="line">| <span class="number">1</span> | 张三 | <span class="number">15</span> |</span><br><span class="line">| <span class="number">2</span> | 李四 | <span class="number">15</span> |</span><br><span class="line">+----+------+-----+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.012</span>s</span><br><span class="line"><span class="comment">// 我们尝试用刚才回滚的方式进行还原数据</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; rollback;</span><br><span class="line">Query OK, <span class="number">0</span> rows affected</span><br><span class="line">Time: <span class="number">0.000</span>s</span><br><span class="line"><span class="comment">// 发现数据无法回退了,仍然是提交后的数据</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select * <span class="keyword">from</span> user;</span><br><span class="line">+----+------+-----+</span><br><span class="line">| id | name | age |</span><br><span class="line">+----+------+-----+</span><br><span class="line">| <span class="number">1</span> | 张三 | <span class="number">15</span> |</span><br><span class="line">| <span class="number">2</span> | 李四 | <span class="number">15</span> |</span><br><span class="line">+----+------+-----+</span><br><span class="line"><span class="number">2</span> rows <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.017</span>s</span><br><span class="line">PHP 实现事务实例代码</span><br><span class="line"></span><br><span class="line">&lt;?php</span><br><span class="line"><span class="comment">// 连接MySQL</span></span><br><span class="line">$mysqli = <span class="keyword">new</span> mysqli(<span class="string">'127.0.0.1'</span>, <span class="string">'root'</span>, <span class="string">'123456'</span>, <span class="string">'test'</span>, <span class="number">3306</span>);</span><br><span class="line"><span class="comment">// 关闭事务自动提交</span></span><br><span class="line">$mysqli-&gt;autocommit(<span class="literal">false</span>);</span><br><span class="line"><span class="comment">// 1.开启事务</span></span><br><span class="line">$mysqli-&gt;begin_transaction();</span><br><span class="line"><span class="comment">// 2.修改数据</span></span><br><span class="line">$mysqli-&gt;query(<span class="string">"update user set age=10 where id=1"</span>);</span><br><span class="line"><span class="comment">// 3.查看数据</span></span><br><span class="line">$mysqli-&gt;query(<span class="string">"select * from user"</span>);</span><br><span class="line"><span class="comment">// 4.事务回滚</span></span><br><span class="line">$mysqli-&gt;rollback();</span><br><span class="line"><span class="comment">// 5.查看数据</span></span><br><span class="line">$mysqli-&gt;query(<span class="string">"select * from user"</span>);</span><br><span class="line"><span class="comment">// 7.修改数据</span></span><br><span class="line">$mysqli-&gt;query(<span class="string">"update user set age=15 where id=1"</span>);</span><br><span class="line"><span class="comment">// 8.事务提交</span></span><br><span class="line">$mysqli-&gt;commit();</span><br><span class="line"><span class="comment">// 9.事务回滚</span></span><br><span class="line">$mysqli-&gt;rollback();</span><br><span class="line"><span class="comment">// 10.查看数据</span></span><br><span class="line">$mysqli-&gt;query(<span class="string">"select * from user"</span>);</span><br><span class="line">如何设置事务的隔离级别</span><br><span class="line"><span class="comment">// 查看当前的事务隔离级别</span></span><br><span class="line">mysql root@<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:test&gt; select @@tx_isolation;</span><br><span class="line">+-----------------+</span><br><span class="line">| @@tx_isolation |</span><br><span class="line">+-----------------+</span><br><span class="line">| REPEATABLE-READ |</span><br><span class="line">+-----------------+</span><br><span class="line"><span class="number">1</span> row <span class="keyword">in</span> set</span><br><span class="line">Time: <span class="number">0.015</span>s</span><br><span class="line"><span class="comment">// 设置隔离级别</span></span><br><span class="line">set session transaction isolation level 隔离级别(上面事务隔离级别中的英文单词);</span><br><span class="line">https:<span class="comment">//learnku.com/articles/33749</span></span><br></pre></td></tr></table></figure>
<h3 id="二进制转图片"><a href="#二进制转图片" class="headerlink" title="二进制转图片"></a>二进制转图片</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Created by 独自等待</span></span><br><span class="line"><span class="comment"> * Date: 2014/11/12</span></span><br><span class="line"><span class="comment"> * Time: 10:10</span></span><br><span class="line"><span class="comment"> * Name: decode.php</span></span><br><span class="line"><span class="comment"> * 独自等待博客：https://www.waitalone.cn/11-game.html</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> $bin = &lt;&lt;&lt;binary</span><br><span class="line">01001000 00110100 01110011 01001001 01000001 01000011 01001010 01001011 #第1行</span><br><span class="line">#为阅读方便，把第1行和最后1行之间的省略了，大家测试的时候请把二进制代码放到这里</span><br><span class="line">01001010 01000001 01000001 01101111 01000001 01000001 01000001 00111101 #最后1行</span><br><span class="line">binary;</span><br><span class="line">$bin_arr = explode(' ',str_replace("\r\n"," ",$bin));</span><br><span class="line">#print_r($bin_arr);</span><br><span class="line">$dec = '';</span><br><span class="line">foreach ($bin_arr as $bin_code) &#123;</span><br><span class="line">    $dec .= chr(bindec($bin_code));</span><br><span class="line">&#125;</span><br><span class="line">echo $dec;</span><br><span class="line">fwrite(fopen('key.tar.gz','wb'),base64_decode($dec));</span><br><span class="line"></span><br><span class="line">chr(bindec('01110011'))//s</span><br><span class="line">import base64</span><br><span class="line">bin = '''</span><br><span class="line">01001000 00110100 01110011 01001001 01000001 01000011 01001010 01001011 #第1行</span><br><span class="line">#为阅读方便，把第1行和最后1行之间的省略了，大家测试的时候请把二进制代码放到这里</span><br><span class="line">01001010 01000001 01000001 01101111 01000001 01000001 01000001 00111101 #最后1行</span><br><span class="line">'''</span><br><span class="line">binTochar = [chr(int(x, 2)) for x in bin.strip().split()]</span><br><span class="line">print ''.join(binTochar)</span><br><span class="line">keyFile = open('key.tar.gz', 'wb')</span><br><span class="line">keyFile.write(base64.b64decode(''.join(binTochar)))</span><br><span class="line">keyFile.close()</span><br></pre></td></tr></table></figure>
<h3 id="windos-安装-Laravel-horizon"><a href="#windos-安装-Laravel-horizon" class="headerlink" title="windos 安装 Laravel/horizon"></a>windos 安装 Laravel/horizon</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">composer.json 中增加以下两个字段：<span class="string">"platform"</span>: &#123; <span class="string">"ext-pcntl"</span>: <span class="string">"7.2"</span>, <span class="string">"ext-posix"</span>: <span class="string">"7.2"</span>&#125;，增加至 config 字段中，再次运行安装命令即可～</span><br></pre></td></tr></table></figure>
<h3 id="回调函数"><a href="#回调函数" class="headerlink" title="回调函数"></a>回调函数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">$array = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>];</span><br><span class="line">$str = array_reduce($array, <span class="function"><span class="keyword">function</span> (<span class="params">$return_str, $value</span>) </span>&#123;</span><br><span class="line">    $return_str = $return_str . $value;  <span class="comment">//层层迭代</span></span><br><span class="line">    <span class="keyword">return</span> $return_str;</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">// 一个基本的购物车，包括一些已经添加的商品和每种商品的数量。</span></span><br><span class="line"><span class="comment">// 其中有一个方法用来计算购物车中所有商品的总价格，该方法使</span></span><br><span class="line"><span class="comment">// 用了一个 closure 作为回调函数。</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Cart</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">const</span> PRICE_BUTTER  = <span class="number">1.00</span>;</span><br><span class="line">    <span class="keyword">const</span> PRICE_MILK    = <span class="number">3.00</span>;</span><br><span class="line">    <span class="keyword">const</span> PRICE_EGGS    = <span class="number">6.95</span>;</span><br><span class="line"></span><br><span class="line">    protected   $products = array();</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">add</span>(<span class="params">$product, $quantity</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;products[$product] = $quantity;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getQuantity</span>(<span class="params">$product</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> isset($<span class="keyword">this</span>-&gt;products[$product]) ? $<span class="keyword">this</span>-&gt;products[$product] :</span><br><span class="line">               FALSE;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getTotal</span>(<span class="params">$tax</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $total = <span class="number">0.00</span>;</span><br><span class="line"></span><br><span class="line">        $callback =</span><br><span class="line">            <span class="function"><span class="keyword">function</span> (<span class="params">$quantity, $product</span>) <span class="title">use</span> (<span class="params">$tax, &amp;$total</span>)</span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                <span class="comment">//定义一个回调函数 取出 当前商品的价格</span></span><br><span class="line">                $pricePerItem = constant(__CLASS__ . <span class="string">"::PRICE_"</span> .</span><br><span class="line">                    strtoupper($product));</span><br><span class="line">                $total += ($pricePerItem * $quantity) * ($tax + <span class="number">1.0</span>);</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">        array_walk($<span class="keyword">this</span>-&gt;products, $callback);</span><br><span class="line">        <span class="keyword">return</span> round($total, <span class="number">2</span>);;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$my_cart = <span class="keyword">new</span> Cart;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 往购物车里添加条目</span></span><br><span class="line">$my_cart-&gt;add(<span class="string">'butter'</span>, <span class="number">1</span>);</span><br><span class="line">$my_cart-&gt;add(<span class="string">'milk'</span>, <span class="number">3</span>);</span><br><span class="line">$my_cart-&gt;add(<span class="string">'eggs'</span>, <span class="number">6</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 打出出总价格，其中有 5% 的销售税.</span></span><br><span class="line">print $my_cart-&gt;getTotal(<span class="number">0.05</span>) . <span class="string">"\n"</span>;</span><br><span class="line"><span class="comment">// 最后结果是 54.29</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/33848</span></span><br></pre></td></tr></table></figure>
<h3 id="并发问题"><a href="#并发问题" class="headerlink" title="并发问题"></a>并发问题</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">//正常写法,获取最后一条数据，新的单据编号+1，有并发问题</span></span><br><span class="line">        $last = Article::orderByDesc(<span class="string">'id'</span>)-&gt;first();</span><br><span class="line">        $data = [</span><br><span class="line">            <span class="string">'code'</span>    =&gt; $last-&gt;code + <span class="number">1</span>,</span><br><span class="line">        ];</span><br><span class="line">        $article = Article::create($data);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//---------------------------------------------------------------------------------//</span></span><br><span class="line">        <span class="comment">//解决并发问题  测试ab -t 6 -c 20 http://study.local/xxx</span></span><br><span class="line">        DB::beginTransaction();</span><br><span class="line">        $last = Article::lockForUpdate()-&gt;orderByDesc(<span class="string">'id'</span>)-&gt;first();</span><br><span class="line">        $data = [</span><br><span class="line">            <span class="string">'code'</span>    =&gt; $last-&gt;code + <span class="number">1</span>,</span><br><span class="line">        ];</span><br><span class="line">        $article = Article::create($data);</span><br><span class="line">        DB::commit();</span><br><span class="line">        https:<span class="comment">//learnku.com/articles/33809</span></span><br><span class="line">高性能分布式并发锁, 行为限流https:<span class="comment">//github.com/zhaocong6/lock</span></span><br></pre></td></tr></table></figure>
<h3 id="intervention-image慢"><a href="#intervention-image慢" class="headerlink" title="intervention/image慢"></a>intervention/image慢</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 记录开始时间</span></span><br><span class="line">$startTimestamp = microtime(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">$url = <span class="string">'http://wx.qlogo.cn/mmopen/XxT9TiaJ1ibf06TNRCMjQADS4opDHvQLguLZHpqkRlvuJYZicvJW4iaOalPsKIs0kpZ3F6864ZzibyObYiaucUQSrdp4pFTNDyIpxw/0'</span>;</span><br><span class="line"></span><br><span class="line">$avatar = \Image::make($url);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 记录结束时间</span></span><br><span class="line">$endTimestamp = microtime(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">info($startTimestamp);</span><br><span class="line">info($endTimestamp);</span><br><span class="line">info($endTimestamp - $startTimestamp);</span><br><span class="line"></span><br><span class="line">$startTimestamp = microtime(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">$client = <span class="keyword">new</span> \GuzzleHttp\Client();</span><br><span class="line"></span><br><span class="line">$url = <span class="string">'http://wx.qlogo.cn/mmopen/XxT9TiaJ1ibf06TNRCMjQADS4opDHvQLguLZHpqkRlvuJYZicvJW4iaOalPsKIs0kpZ3F6864ZzibyObYiaucUQSrdp4pFTNDyIpxw/0'</span>;</span><br><span class="line"></span><br><span class="line">$avatarResponse = $client-&gt;get($url);</span><br><span class="line"></span><br><span class="line">$avatar = \Image::make($avatarResponse-&gt;getBody()-&gt;getContents());</span><br><span class="line"></span><br><span class="line">$endTimestamp = microtime(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">info($startTimestamp);</span><br><span class="line">info($endTimestamp);</span><br><span class="line">info($endTimestamp - $startTimestamp);</span><br><span class="line"> https:<span class="comment">//tianyong90.com/posts/intervention-image-zhong-de-yi-ge-xiao-keng-ji-qi-po-jie-zhi-fa/</span></span><br><span class="line">在这里我先使用 GuzzleHttp 获取头像，再使用 Image::make($data) 创建头像</span><br></pre></td></tr></table></figure>
<h3 id="laravel5-5-中读写分离"><a href="#laravel5-5-中读写分离" class="headerlink" title="laravel5.5 中读写分离"></a>laravel5.5 中读写分离</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">明明刚刚写入了数据，但查询时却报 No query result ，而且只是偶然性出现，没啥规律。 在没有启用 sticky 的时候，使用 write 连接写入数据后立即读取，读取时使用的是 read 连接，这样就有可能出问题。将 sticky 设置为 <span class="literal">true</span> 后，在与这个写入操作相同的请求周期内的后续读取操作，仍然使用原来的 write 连接，就不会有这麻烦了。</span><br></pre></td></tr></table></figure>
<h3 id="puppeteer-采集异步加载"><a href="#puppeteer-采集异步加载" class="headerlink" title="puppeteer 采集异步加载"></a>puppeteer 采集异步加载</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> spatie/browsershot</span><br><span class="line">npm i puppeteer --save</span><br><span class="line">use Spatie\Browsershot\Browsershot;</span><br><span class="line"></span><br><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">getBodyHtml</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $newsUrl = <span class="string">'https://m.toutiao.com/i6546884151050502660/'</span>;</span><br><span class="line"></span><br><span class="line">    $html = Browsershot::url($newsUrl)</span><br><span class="line">        -&gt;windowSize(<span class="number">480</span>, <span class="number">800</span>)</span><br><span class="line">        -&gt;userAgent(<span class="string">'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36'</span>)</span><br><span class="line">        -&gt;mobile()</span><br><span class="line">        -&gt;touch()</span><br><span class="line">        -&gt;bodyHtml();</span><br><span class="line"></span><br><span class="line">    \Log::info($html);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">use Spatie\Browsershot\Browsershot;</span><br><span class="line"></span><br><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">getBodyHtml</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $newsUrl = <span class="string">'https://m.toutiao.com/i6546884151050502660/'</span>;</span><br><span class="line"></span><br><span class="line">    Browsershot::url($newsUrl)</span><br><span class="line">        -&gt;windowSize(<span class="number">480</span>, <span class="number">800</span>)</span><br><span class="line">        -&gt;userAgent(<span class="string">'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36'</span>)</span><br><span class="line">        -&gt;mobile()</span><br><span class="line">        -&gt;touch()</span><br><span class="line">        -&gt;setDelay(<span class="number">1000</span>)</span><br><span class="line">        -&gt;save(public_path(<span class="string">'images/toutiao.jpg'</span>));</span><br><span class="line">&#125;https:<span class="comment">//tianyong90.com/posts/laravel-zhong-shi-yong-puppeteer-cai-ji-yi-bu-jia-zai-de-wang-ye-nei-rong/</span></span><br></pre></td></tr></table></figure>
<h3 id="session-与-cookie"><a href="#session-与-cookie" class="headerlink" title="session 与 cookie"></a>session 与 cookie</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"> cookie运行原理</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span> 客户端向服务端发起一个 http 请求.</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span> 服务端设置一个创建 cookie 的指令，响应给客户端.</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 客户端收到服务端响应的指令，根据指令在客户端创建一个 cookie.</span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> 挡下一次请求时，客户端携带这个 cookie 向服务端发送请求.</span><br><span class="line">session. 运行原理</span><br><span class="line">       </span><br><span class="line">       <span class="number">1.</span> 客户端向服务端发起请求，建立通信</span><br><span class="line">       </span><br><span class="line">       <span class="number">2.</span> 服务端根据设置的 session 创建指令，在服务端创建一个编号为 sessionid 的文件，里面的值就是 session 具体的值 (组成部分 变量名 | 类型 : 长度：值).</span><br><span class="line">       </span><br><span class="line">       <span class="number">3.</span> 服务端将创建好的 sessionid 编号响应给客户端，客户则将该编号存在 cookie 中 (一般我们在浏览器存储的调试栏中会发现 cookie 中有一个 PHPSESSID 的键，这就是 sessionid，当然这个名称，我可以通过设置服务端是可以改变的).</span><br><span class="line">       </span><br><span class="line">       . 当下一次请求时，客户端将这个 sessionid 携带在请求中，发送给服务端，服务端根据这个 sessionid 来做一些业务判断</span><br></pre></td></tr></table></figure>
<h3 id="PHP-Casbin-的-ABAC-权限控制"><a href="#PHP-Casbin-的-ABAC-权限控制" class="headerlink" title="PHP-Casbin 的 ABAC 权限控制"></a>PHP-Casbin 的 ABAC 权限控制</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//github.com/php-casbin/php-casbin</span></span><br><span class="line">ABAC 的官方实例如下:</span><br><span class="line"></span><br><span class="line">[request_definition]</span><br><span class="line">r = sub, obj, act</span><br><span class="line"></span><br><span class="line">[policy_definition]</span><br><span class="line">p = sub, obj, act</span><br><span class="line"></span><br><span class="line">[policy_effect]</span><br><span class="line">e = some(where (p.eft == allow))</span><br><span class="line"></span><br><span class="line">[matchers]</span><br><span class="line">m = r.sub == r.obj.owner</span><br><span class="line">这是 r.obj 类的定义:</span><br><span class="line"></span><br><span class="line">$data1 = <span class="keyword">new</span> \stdClass();</span><br><span class="line">$data1-&gt;name = <span class="string">'data1'</span>;</span><br><span class="line">$data1-&gt;owner = <span class="string">'alice'</span>;</span><br><span class="line"></span><br><span class="line">$data2 = <span class="keyword">new</span> \stdClass();</span><br><span class="line">$data2-&gt;name = <span class="string">'data2'</span>;</span><br><span class="line">$data2-&gt;owner = <span class="string">'bob'</span>;</span><br><span class="line">然后使用决策器进行决策:</span><br><span class="line"></span><br><span class="line">$e-&gt;enforce(<span class="string">'alice'</span>, $data1, <span class="string">'read'</span>);  <span class="comment">// true</span></span><br><span class="line">$e-&gt;enforce(<span class="string">'alice'</span>, $data2, <span class="string">'read'</span>);  <span class="comment">// false</span></span><br><span class="line"></span><br><span class="line">$e-&gt;enforce(<span class="string">'bob'</span>, $data1, <span class="string">'read'</span>);  <span class="comment">// false</span></span><br><span class="line">$e-&gt;enforce(<span class="string">'bob'</span>, $data2, <span class="string">'read'</span>);  <span class="comment">// true</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/33921</span></span><br></pre></td></tr></table></figure>
<h3 id="php-artisan-tinker-edit"><a href="#php-artisan-tinker-edit" class="headerlink" title="php artisan tinker edit"></a>php artisan tinker edit</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">php artisan tinker</span><br><span class="line">&gt;&gt;&gt;edit</span><br><span class="line"></span><br><span class="line">进入了 Vim 文本状态，能够正常的编写你想要的代码 编辑完之后，我们保存并退出这个文件，tinker 会自动执行我们刚才写好的代码，并将结果进行输出。</span><br><span class="line">也可以考虑使用 spatie/laravel-web-tinker </span><br><span class="line">还有一种方法是 直接把代码写到 php 文件里，然后 php artisan tinker your-file.php 也是我常用的一种解决方法。</span><br><span class="line"> psysh 更多使用可以查看文档 https:<span class="comment">//psysh.org/  https://learnku.com/laravel/t/33957</span></span><br></pre></td></tr></table></figure>
<h3 id="使用-PHP-version-切换-PHP-版本"><a href="#使用-PHP-version-切换-PHP-版本" class="headerlink" title="使用 PHP-version 切换 PHP 版本"></a>使用 PHP-version 切换 PHP 版本</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[qian@bogon ~ ]$ mkdir $HOME/.local</span><br><span class="line">[qian@bogon ~ ]$ cd $HOME/.local</span><br><span class="line">[qian@bogon .local ]$ git clone https:<span class="comment">//github.com/wilmoore/php-version.git</span></span><br><span class="line">[qian@bogon .local ]$ source $HOME/.local/php-version/php-version.sh</span><br><span class="line"><span class="comment">//测试  查看当前php版本</span></span><br><span class="line">[qian@bogon .local ]$ php-version</span><br><span class="line">* <span class="number">7.1</span><span class="number">.18</span></span><br><span class="line"> <span class="number">7.2</span><span class="number">.22</span></span><br><span class="line">[qian@bogon ~ ]$ echo <span class="string">"source $HOME/.local/php-version/php-version.sh"</span> &gt;&gt; ~<span class="regexp">/.zshrc</span></span><br><span class="line"><span class="regexp">[qian@bogon ~ ]$ source ~/</span>.zshrc</span><br><span class="line">切换 php 版本</span><br><span class="line"></span><br><span class="line">php-version <span class="number">7.1</span></span><br><span class="line">或</span><br><span class="line">php-version <span class="number">7.2</span></span><br></pre></td></tr></table></figure>
<h3 id="动态绘制会员卡图片"><a href="#动态绘制会员卡图片" class="headerlink" title="动态绘制会员卡图片"></a>动态绘制会员卡图片</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * PHP GD 动态绘制会员卡图片</span></span><br><span class="line"><span class="comment"> * https://github.com/kasuganosoras/SomeCodes/blob/master/v2ex_600721.php</span></span><br><span class="line"><span class="comment"> * 帖子：https://www.v2ex.com/t/600721</span></span><br><span class="line"><span class="comment"> * 更新：现在背景图黑色部分不会变成透明了</span></span><br><span class="line"><span class="comment"> * 测试：https://cdn.zerodream.net/api/card/</span></span><br><span class="line"><span class="comment"> * 使用：Clone 到本地后，将 v2ex_600721.php 和 v2ex_600721 目录复制到你的网站目录下即可</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">// 获取图片大小</span></span><br><span class="line">list($width, $height, $type) = getimagesize(__DIR__ . <span class="string">'/v2ex_600721/images/bg.png'</span>);</span><br><span class="line"><span class="comment">// 文字内容设定</span></span><br><span class="line">$text    = <span class="string">"钢板卡号：4040 2333 114 514"</span>;</span><br><span class="line"><span class="comment">// 加载资源</span></span><br><span class="line">$font    = __DIR__ . <span class="string">'/v2ex_600721/fonts/mono.ttf'</span>;</span><br><span class="line">$card    = imagecreatefrompng(__DIR__ . <span class="string">'/v2ex_600721/images/bg.png'</span>);</span><br><span class="line">$image   = imagecreatetruecolor($width, $height);</span><br><span class="line">$bgColor = imagecolorallocatealpha($image, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">127</span>);</span><br><span class="line">$white   = imagecolorallocate($image, <span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>);</span><br><span class="line"><span class="comment">// 执行绘图</span></span><br><span class="line">imagefill($image, <span class="number">0</span>, <span class="number">0</span>, $bgColor);</span><br><span class="line">imagecopyresampled($image, $card, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, $width, $height, $width, $height);</span><br><span class="line">imagefttext($image, <span class="number">12</span>, <span class="number">0</span>, <span class="number">36</span>, <span class="number">215</span>, $white, $font, $text);</span><br><span class="line">imagesavealpha($image, <span class="literal">true</span>);</span><br><span class="line"><span class="comment">// 输出并销毁</span></span><br><span class="line">Header(<span class="string">"Content-type: image/png"</span>);</span><br><span class="line">imagepng($image);</span><br><span class="line">imagedestroy($image);</span><br></pre></td></tr></table></figure>
<h3 id="PHP不支持Unicode编码"><a href="#PHP不支持Unicode编码" class="headerlink" title="PHP不支持Unicode编码"></a>PHP不支持Unicode编码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//文件编码UTF-8</span></span><br><span class="line">echo strlen(<span class="string">"中文"</span>); <span class="comment">// 6</span></span><br><span class="line">echo substr(<span class="string">"中文"</span>,<span class="number">0</span>,<span class="number">1</span>) <span class="comment">// 乱码</span></span><br><span class="line">echo substr(<span class="string">"中文"</span>,<span class="number">0</span>,<span class="number">3</span>) <span class="comment">// 中</span></span><br><span class="line">PHP原生字符串函数只能操作单字节字符！就是把一个字节当做一个字符来处理！</span><br><span class="line"><span class="comment">//文件编码UTF-8</span></span><br><span class="line">echo bin2hex(<span class="string">"中文"</span>); <span class="comment">// 可以看到，"中文"对应的二进制就是：e4b8ade69687</span></span><br><span class="line">echo strlen(<span class="string">"中文"</span>); <span class="comment">// 所以按照单字节来统计长度，就是6 </span></span><br><span class="line">echo substr(<span class="string">"中文"</span>,<span class="number">0</span>,<span class="number">1</span>) <span class="comment">// 取0到1个字节，也就是e4，并不对应某个字符的编码，所以乱码</span></span><br><span class="line">echo substr(<span class="string">"中文"</span>,<span class="number">0</span>,<span class="number">3</span>) <span class="comment">// 取0到3个字节，刚好把`中`的编码取出来</span></span><br><span class="line"><span class="comment">// 脚本类型为UTF-8</span></span><br><span class="line">echo strlen(<span class="string">"中文"</span>); <span class="comment">// 6</span></span><br><span class="line">echo mb_strlen(<span class="string">"中文"</span>,<span class="string">"UTF-8"</span>); <span class="comment">//2  使用mb_strlen ，并传入编码 utf-8, 就会把二进制E4B8ADE69687当做utf-8的处理能正确处理</span></span><br><span class="line">echo mb_strlen(<span class="string">"中文"</span>); <span class="comment">//2  如果不传编码UTF-8,则函数会自动确定编码，文档说：如果省略，则使用内部字符编码。所以这里也当做UTF-8来处理。</span></span><br><span class="line">echo mb_strlen(<span class="string">"中文"</span>,<span class="string">"GBK"</span>); <span class="comment">//3，如果传入编码GBK，则：e4b8ade69687会被当做gbk来处理，一个gbk字符占2字节，所以为：3</span></span><br><span class="line">http:<span class="comment">//webkit.cc/post/php-and-unicode.html</span></span><br></pre></td></tr></table></figure>
<h3 id="curl乱码"><a href="#curl乱码" class="headerlink" title="curl乱码"></a>curl乱码</h3><p>php curl乱码 curl_setopt ($ch, CURLOPT_ENCODING ,’gzip’);<br>是告诉 Curl 使用 Gzip 进行解析。 Header 里 Accept-Encoding:gzip 是告诉对方服务器使用 Gzip 进行传输。 ​​​​</p>
<p>curl_setopt($ch, CURLOPT_ENCODING, ‘’);<br>加了这句话，会在请求时自动加上请求头Accept-Encoding，并且返回内容会自动解压，不会乱码了</p>
<h3 id="PHP-进化史"><a href="#PHP-进化史" class="headerlink" title="PHP 进化史"></a>PHP 进化史</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">匿名类的支持</span><br><span class="line"><span class="keyword">new</span> <span class="class"><span class="keyword">class</span>($<span class="title">i</span>) </span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$i</span>) </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;i = $i;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 使用 &lt;=&gt; （飞船符）之后</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">order_func</span>(<span class="params">$a, $b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> $a &lt;=&gt; $b;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 分组使用语法:</span></span><br><span class="line"></span><br><span class="line">use FooLibrary\Bar\Baz\&#123; ClassA, ClassB, ClassC, ClassD <span class="keyword">as</span> Fizbo &#125;;</span><br><span class="line"></span><br><span class="line">echo <span class="string">"\u&#123;202E&#125;Reversed text"</span>; <span class="comment">//输出反转文本</span></span><br><span class="line">echo <span class="string">"mañana"</span>; <span class="comment">// "ma\u&#123;00F1&#125;ana"</span></span><br><span class="line">echo <span class="string">"mañana"</span>; <span class="comment">// "man\u&#123;0303&#125;ana" "n" 结合 ~ 字符 (U+0303)</span></span><br><span class="line"></span><br><span class="line">$array = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line"><span class="comment">//为 $a，$b 和 $c 按键值从 0 开始的方式分配 $array 数组元素的值</span></span><br><span class="line">[$a, $b, $c] = $array;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 使用 “a”，“b” 和 “c” 键分别为 $a，$b 和 $c 分配 $array 中数组元素的值</span></span><br><span class="line">[<span class="string">"a"</span> =&gt; $a, <span class="string">"b"</span> =&gt; $b, <span class="string">"c"</span> =&gt; $c] = $array;</span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">   <span class="comment">// 部分代码...</span></span><br><span class="line">&#125; <span class="keyword">catch</span> (ExceptionType1 | ExceptionType2 $e) &#123;</span><br><span class="line">   <span class="comment">// 处理异常的代码</span></span><br><span class="line">&#125; <span class="keyword">catch</span> (\Exception $e) &#123;</span><br><span class="line">   <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/php/t/33829</span></span><br></pre></td></tr></table></figure>
<h3 id="单例模式"><a href="#单例模式" class="headerlink" title="单例模式"></a>单例模式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 单例模式</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Single</span></span></span><br><span class="line"><span class="class"></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> $attribute = <span class="string">''</span>;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> $instance = <span class="string">''</span>;</span><br><span class="line"></span><br><span class="line">    private <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$attribute = <span class="string">'浪子编程走四方'</span></span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        self::$attribute = $attribute;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">getInstance</span>(<span class="params">$attribute = <span class="string">'浪子编程走四方1'</span></span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (!(self::$instance <span class="keyword">instanceof</span> self)) self::$instance = <span class="keyword">new</span> self($attribute);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> self::$instance;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 工厂模式</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Factory</span></span></span><br><span class="line"><span class="class"></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">createObj</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> Single::getInstance(<span class="string">'浪子编程走四方'</span>);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 注册模式</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 含义:就是将对象放在一个对象池中，使用的时候直接去对象池查找.</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 需要如下几个操作:</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 1.注册</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 2.存放对象池</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 3.获取</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> * 4.销毁</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line">Class Register</span><br><span class="line"></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 用一个数组来当做对象池，键当做对象别名，值存储具体对象</span></span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> $objTree = [];</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 将对象放在对象池</span></span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">set</span>(<span class="params">$key, $val</span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> self::$objTree[$key] = $val;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 通过对象别名在对象池中获取到对象别名</span></span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">get</span>(<span class="params">$key</span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> self::$objTree[$key];</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">\</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 通过对象别名将对象从对象池中注销https://learnku.com/articles/34160</span></span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">_unset</span>(<span class="params">$key</span>)</span></span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">        unset(self::$objTree[$key]);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Register::set(<span class="string">'single'</span>, <span class="attr">Factory</span>::createObj());</span><br><span class="line"></span><br><span class="line">$single = Register::get(<span class="string">'single'</span>);</span><br><span class="line"></span><br><span class="line">print_r($single);</span><br><span class="line"></span><br><span class="line">echo $single::$attribute;</span><br></pre></td></tr></table></figure>
<h3 id="guzzle-绑定-host"><a href="#guzzle-绑定-host" class="headerlink" title="guzzle 绑定 host"></a>guzzle 绑定 host</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line">$response = $client-&gt;get(<span class="string">'http://1.2.3.4'</span>,[<span class="string">"timeout"</span>=&gt;<span class="number">1</span>,<span class="string">"connect_timeout"</span>=&gt;<span class="number">1</span>,<span class="string">'headers'</span>=&gt;[<span class="string">'host'</span>=&gt;<span class="string">'xxx.com.cn'</span>]]);</span><br><span class="line">$status = $response-&gt;getStatusCode();</span><br><span class="line"><span class="keyword">if</span> ($status == <span class="number">200</span>)</span><br><span class="line">&#123;</span><br><span class="line">    $data=json_decode((string)$response-&gt;getBody(), <span class="literal">true</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">return</span> <span class="literal">false</span>;</span><br></pre></td></tr></table></figure>
<h3 id="指定顺序插入数组元素"><a href="#指定顺序插入数组元素" class="headerlink" title="指定顺序插入数组元素"></a>指定顺序插入数组元素</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">在数组第<span class="number">2</span>,<span class="number">4</span>个位置插入一个数组</span><br><span class="line">$insert = [</span><br><span class="line">    [<span class="string">'index'</span>=&gt; <span class="number">2</span>, <span class="string">'data'</span> =&gt; <span class="string">'第2'</span>],</span><br><span class="line">    [<span class="string">'index'</span>=&gt; <span class="number">4</span>, <span class="string">'data'</span> =&gt; <span class="string">'第4'</span>],</span><br><span class="line">];</span><br><span class="line">$data = [</span><br><span class="line">    [<span class="string">'a'</span> =&gt; <span class="string">'a'</span>],</span><br><span class="line">    [<span class="string">'b'</span> =&gt; <span class="string">'b'</span>],</span><br><span class="line">    [<span class="string">'c'</span> =&gt; <span class="string">'c'</span>],</span><br><span class="line">    [<span class="string">'d'</span> =&gt; <span class="string">'d'</span>],</span><br><span class="line">    [<span class="string">'e'</span> =&gt; <span class="string">'e'</span>],</span><br><span class="line">    [<span class="string">'f'</span> =&gt; <span class="string">'f'</span>],</span><br><span class="line">];</span><br><span class="line">$i = <span class="number">0</span>;</span><br><span class="line">foreach ($insert <span class="keyword">as</span> $value) &#123;</span><br><span class="line">    <span class="keyword">if</span> (!$value) &#123;</span><br><span class="line">        <span class="keyword">continue</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    array_splice($data, $value[<span class="string">'index'</span>] - <span class="number">1</span> + $i, <span class="number">0</span> ,[$value]);</span><br><span class="line">    $i++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">print_r($data);</span><br><span class="line"></span><br><span class="line"> [                     </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"a"</span> =&gt; <span class="string">"a"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"index"</span> =&gt; <span class="number">2</span>,     </span><br><span class="line">     <span class="string">"data"</span> =&gt; <span class="string">"第2"</span>,   </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"b"</span> =&gt; <span class="string">"b"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"c"</span> =&gt; <span class="string">"c"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"index"</span> =&gt; <span class="number">4</span>,     </span><br><span class="line">     <span class="string">"data"</span> =&gt; <span class="string">"第4"</span>,   </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"d"</span> =&gt; <span class="string">"d"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"e"</span> =&gt; <span class="string">"e"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line">   [                   </span><br><span class="line">     <span class="string">"f"</span> =&gt; <span class="string">"f"</span>,       </span><br><span class="line">   ],                  </span><br><span class="line"> ]</span><br></pre></td></tr></table></figure>
<h3 id="guzzle-并行请求接口"><a href="#guzzle-并行请求接口" class="headerlink" title="guzzle 并行请求接口"></a>guzzle 并行请求接口</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> <span class="string">"guzzlehttp/guzzle: 5.3.1"</span></span><br><span class="line">use GuzzleHttp\Pool;</span><br><span class="line">use GuzzleHttp\Message\Response;</span><br><span class="line">$requests = [];</span><br><span class="line">$url = <span class="string">'http://xxxx.com'</span>;</span><br><span class="line">$url2 = <span class="string">"http://xxx2.com"</span>;</span><br><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line">$request = $client-&gt;createRequest(<span class="string">'get'</span>, $url, [<span class="string">"timeout"</span>=&gt;<span class="number">1</span>,<span class="string">"connect_timeout"</span>=&gt;<span class="number">1</span>]);</span><br><span class="line">$request2 = $client-&gt;createRequest(<span class="string">'get'</span>, $url2, [<span class="string">"timeout"</span>=&gt;<span class="number">1</span>,<span class="string">"connect_timeout"</span>=&gt;<span class="number">1</span>]);</span><br><span class="line">$requests[] = $request;</span><br><span class="line">$requests[] = $request2;</span><br><span class="line">$results = Pool::batch($client, $requests);</span><br><span class="line"><span class="keyword">if</span>(!$results-&gt;getResult($request) <span class="keyword">instanceof</span> Response &amp;&amp; !$results-&gt;getResult($request2) <span class="keyword">instanceof</span> Response)&#123;</span><br><span class="line">    <span class="keyword">return</span> [];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>($results-&gt;getFailures())&#123;</span><br><span class="line">    $data = [];</span><br><span class="line">    $data2 = [];</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    $data = $results-&gt;getResult($request)-&gt;json();</span><br><span class="line">    $data2 = $results-&gt;getResult($request2)-&gt;json();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">return</span> [$data,$data2];</span><br><span class="line">异步请求</span><br><span class="line"><span class="keyword">try</span>&#123;</span><br><span class="line">    $client = <span class="keyword">new</span> Client();</span><br><span class="line">    $req = $client-&gt;createRequest(<span class="string">'GET'</span>, <span class="string">'http://xxx.com?'</span>, [<span class="string">'future'</span> =&gt; <span class="literal">true</span>,<span class="string">"timeout"</span>=&gt;<span class="number">1</span>,<span class="string">"connect_timeout"</span>=&gt;<span class="number">1</span>]);</span><br><span class="line">    $client-&gt;send($req)-&gt;then(<span class="function"><span class="keyword">function</span> (<span class="params">$response</span>)</span>&#123;</span><br><span class="line">    <span class="comment">//dump($response-&gt;json());</span></span><br><span class="line">    &#125;);</span><br><span class="line">&#125; <span class="keyword">catch</span> (\Exception $e)&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="杀掉过期进程"><a href="#杀掉过期进程" class="headerlink" title="杀掉过期进程"></a>杀掉过期进程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">use Carbon\Carbon;</span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">            $pids = $<span class="keyword">this</span>-&gt;getPids([<span class="string">"php"</span>, <span class="string">"lock"</span>]);</span><br><span class="line">            foreach ($pids <span class="keyword">as</span> $pid) &#123;</span><br><span class="line">                $startTime = $<span class="keyword">this</span>-&gt;getProcessStartTime($pid);</span><br><span class="line">                $<span class="keyword">this</span>-&gt;ifKill($startTime, $pid);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">getPids</span>(<span class="params">$arr</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $command = <span class="string">"ps aux | grep -v grep "</span>;</span><br><span class="line">        foreach ($arr <span class="keyword">as</span> $word) &#123;</span><br><span class="line">            $command .= <span class="string">"| grep &#123;$word&#125;"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $command .= <span class="string">" | awk '&#123;print $2&#125;'"</span>;</span><br><span class="line">        $result = shell_exec($command);</span><br><span class="line">        $result = trim($result);</span><br><span class="line">        <span class="keyword">if</span> (empty($result)) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">"Cannot find such process "</span> . implode(<span class="string">","</span>, $arr));</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> explode(<span class="string">"\n"</span>, $result);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">getProcessStartTime</span>(<span class="params">$pid</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $command = <span class="string">"ps -p &#123;$pid&#125; -o lstart"</span>;</span><br><span class="line">        $result = shell_exec($command);</span><br><span class="line">        $result = trim(str_replace(<span class="string">"STARTED"</span>, <span class="string">""</span>, $result));</span><br><span class="line">        <span class="keyword">if</span> (empty($result)) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> Exception(<span class="string">"Cannot get process start time, process id is &#123;$pid&#125;"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        $ctime = Carbon::createFromFormat(<span class="string">"D M j H:i:s Y"</span>, $result);</span><br><span class="line">        <span class="keyword">return</span> $ctime;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">ifKill</span>(<span class="params">Carbon $ctime, $pid</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> ($ctime-&gt;lt(Carbon::now()-&gt;addHours(<span class="number">-1</span>))) &#123;</span><br><span class="line">            $cmd = file_get_contents(<span class="string">"/proc/&#123;$pid&#125;/cmdline"</span>);</span><br><span class="line">            </span><br><span class="line">            shell_exec(<span class="string">"kill -9 &#123;$pid&#125;"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="根据name和pcode合并职位"><a href="#根据name和pcode合并职位" class="headerlink" title="根据name和pcode合并职位"></a>根据name和pcode合并职位</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">$temp = [];</span><br><span class="line">        foreach ($arr <span class="keyword">as</span> $v) &#123;</span><br><span class="line">            <span class="keyword">if</span> (isset($temp[$v[<span class="string">'Name'</span>].<span class="string">'_'</span>.$v[<span class="string">'Pcode'</span>]])) &#123;</span><br><span class="line">                $temp[$v[<span class="string">'Name'</span>].<span class="string">'_'</span>.$v[<span class="string">'Pcode'</span>]][<span class="string">'Duty'</span>] .= <span class="string">' '</span>.$v[<span class="string">'Duty'</span>];</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                $temp[$v[<span class="string">'Name'</span>].<span class="string">'_'</span>.$v[<span class="string">'Pcode'</span>]] = $v;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//职位排序</span></span><br><span class="line">        $manager = [<span class="string">'董事长'</span>, <span class="string">'董事会主席'</span>,  <span class="string">'总裁'</span>, <span class="string">'总经理'</span>];</span><br><span class="line">        $res = [];</span><br><span class="line">        foreach ($manager <span class="keyword">as</span> $value) &#123;</span><br><span class="line">            foreach ($temp <span class="keyword">as</span> $k=&gt;$v) &#123;</span><br><span class="line">                $t = explode(<span class="string">' '</span>, $v[<span class="string">'Duty'</span>]);</span><br><span class="line">                <span class="keyword">if</span> (in_array($value, $t)) &#123;</span><br><span class="line">                    $res[$k] = $v;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//dump($res,$res+array_diff_key($temp,$res),$res+$temp);</span></span><br><span class="line">        <span class="keyword">return</span> $res ? $res + $temp : $temp;</span><br></pre></td></tr></table></figure>
<h3 id="unicode-encode"><a href="#unicode-encode" class="headerlink" title="unicode encode"></a>unicode encode</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">unicode_encode</span>(<span class="params">$name</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $name = iconv(<span class="string">'UTF-8'</span>, <span class="string">'UCS-2'</span>, $name);</span><br><span class="line">    $len = strlen($name);</span><br><span class="line">    $str = <span class="string">''</span>;</span><br><span class="line">    <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $len - <span class="number">1</span>; $i = $i + <span class="number">2</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        $c = $name[$i];</span><br><span class="line">        $c2 = $name[$i + <span class="number">1</span>];</span><br><span class="line">        <span class="keyword">if</span> (ord($c) &gt; <span class="number">0</span>)</span><br><span class="line">        &#123;   <span class="comment">//两个字节的文字</span></span><br><span class="line">            $str .= <span class="string">'\u'</span>.base_convert(ord($c), <span class="number">10</span>, <span class="number">16</span>).str_pad(base_convert(ord($c2), <span class="number">10</span>, <span class="number">16</span>), <span class="number">2</span>, <span class="number">0</span>, STR_PAD_LEFT);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">        &#123;</span><br><span class="line">            $str .= $c2;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $str;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//将UNICODE编码后的内容进行解码</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">unicode_decode</span>(<span class="params">$name</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//转换编码，将Unicode编码转换成可以浏览的utf-8编码</span></span><br><span class="line">    $pattern = <span class="string">'/([\w]+)|(\\\u([\w]&#123;4&#125;))/i'</span>;</span><br><span class="line">    preg_match_all($pattern, $name, $matches);</span><br><span class="line">    <span class="keyword">if</span> (!empty($matches))</span><br><span class="line">    &#123;</span><br><span class="line">        $name = <span class="string">''</span>;</span><br><span class="line">        <span class="keyword">for</span> ($j = <span class="number">0</span>; $j &lt; count($matches[<span class="number">0</span>]); $j++)</span><br><span class="line">        &#123;</span><br><span class="line">            $str = $matches[<span class="number">0</span>][$j];</span><br><span class="line">            <span class="keyword">if</span> (strpos($str, <span class="string">'\\u'</span>) === <span class="number">0</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                $code = base_convert(substr($str, <span class="number">2</span>, <span class="number">2</span>), <span class="number">16</span>, <span class="number">10</span>);</span><br><span class="line">                $code2 = base_convert(substr($str, <span class="number">4</span>), <span class="number">16</span>, <span class="number">10</span>);</span><br><span class="line">                $c = chr($code).chr($code2);</span><br><span class="line">                $c = iconv(<span class="string">'UCS-2'</span>, <span class="string">'UTF-8'</span>, $c);</span><br><span class="line">                $name .= $c;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                $name .= $str;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $name;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="二维数组排序"><a href="#二维数组排序" class="headerlink" title="二维数组排序"></a>二维数组排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//对存储数字的二维数组，按照每个一维数组数字之和的平均值重新排序</span></span><br><span class="line">$arr = array(</span><br><span class="line">		array(<span class="number">1</span>,<span class="number">18</span>,<span class="number">3</span>,<span class="number">6</span>,<span class="number">2147483648</span>),</span><br><span class="line">		array(<span class="number">4</span>,<span class="number">16</span>,<span class="number">2</span>,<span class="number">10</span>,<span class="number">1</span>),</span><br><span class="line">		array(<span class="number">11</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">9</span>),</span><br><span class="line">		array(<span class="number">3</span>,<span class="number">8</span>,<span class="number">12</span>,<span class="number">4</span>,<span class="number">8</span>)</span><br><span class="line">);</span><br><span class="line"><span class="comment">// 方法一</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">vhall_sort</span>(<span class="params">$arr</span>)</span>&#123;</span><br><span class="line">	$tmp = $<span class="keyword">new</span> = array();</span><br><span class="line">	$len = count($arr);</span><br><span class="line">	<span class="keyword">if</span> ($len == <span class="number">0</span> || !is_array($arr)) &#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	foreach ($arr <span class="keyword">as</span> $k=&gt;$v) &#123;</span><br><span class="line">		$num = floatval(array_sum($v));</span><br><span class="line">		$tmp[$k] = $num / $len;</span><br><span class="line">	&#125;</span><br><span class="line">	arsort($tmp);<span class="comment">//倒序排列</span></span><br><span class="line">	foreach ($tmp <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">	    $<span class="keyword">new</span>[$k] = $arr[$k];<span class="comment">//保持key</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $<span class="keyword">new</span>;</span><br><span class="line">&#125;</span><br><span class="line">echo <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">print_r($arr);</span><br><span class="line">print_r(vhall_sort($arr));</span><br><span class="line"><span class="comment">// 方法二 require php5.3+</span></span><br><span class="line">	uasort($arr, <span class="function"><span class="keyword">function</span>(<span class="params">$v1, $v2</span>)</span>&#123; </span><br><span class="line">		<span class="keyword">return</span> (array_sum($v1)/count($v1) &gt; array_sum($v2)/count($v2)) ? <span class="number">-1</span> : <span class="number">1</span>;</span><br><span class="line">	&#125;);</span><br><span class="line">print_r($arr);</span><br><span class="line"><span class="comment">//二维数组去掉重复值</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_unique_fb</span>(<span class="params">$array2D</span>)</span>&#123;</span><br><span class="line">	foreach ($array2D <span class="keyword">as</span> $v)&#123;</span><br><span class="line">		$v=join(<span class="string">','</span>,$v);  <span class="comment">//降维,也可以用implode,将一维数组转换为用逗号连接的字符串</span></span><br><span class="line">		$temp[]=$v;</span><br><span class="line">	&#125;</span><br><span class="line">	$temp=array_unique($temp);    <span class="comment">//去掉重复的字符串,也就是重复的一维数组</span></span><br><span class="line">	foreach ($temp <span class="keyword">as</span> $k =&gt; $v)&#123;</span><br><span class="line">		$temp[$k]=explode(<span class="string">','</span>,$v);   <span class="comment">//再将拆开的数组重新组装</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $temp;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//二维数组去掉重复值,并保留键值</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_unique_fb</span>(<span class="params">$array2D</span>)</span>&#123;</span><br><span class="line">	foreach ($array2D <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">		$v=join(<span class="string">','</span>,$v);  <span class="comment">//降维,也可以用implode,将一维数组转换为用逗号连接的字符串</span></span><br><span class="line">		$temp[$k]=$v;</span><br><span class="line">	&#125;</span><br><span class="line">	$temp=array_unique($temp); <span class="comment">//去掉重复的字符串,也就是重复的一维数组    </span></span><br><span class="line">	foreach ($temp <span class="keyword">as</span> $k =&gt; $v)&#123;</span><br><span class="line">		$array=explode(<span class="string">','</span>,$v); <span class="comment">//再将拆开的数组重新组装</span></span><br><span class="line">		<span class="comment">//下面的索引根据自己的情况进行修改即可</span></span><br><span class="line">		$temp2[$k][<span class="string">'id'</span>] =$array[<span class="number">0</span>];</span><br><span class="line">		$temp2[$k][<span class="string">'title'</span>] =$array[<span class="number">1</span>];</span><br><span class="line">		$temp2[$k][<span class="string">'keywords'</span>] =$array[<span class="number">2</span>];</span><br><span class="line">		$temp2[$k][<span class="string">'content'</span>] =$array[<span class="number">3</span>];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $temp2;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">*二维数组按指定的键值排序</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_sort</span>(<span class="params">$array,$keys,$type=<span class="string">'asc'</span></span>)</span>&#123;</span><br><span class="line">	<span class="keyword">if</span>(!isset($array) || !is_array($array) || empty($array))&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span>(!isset($keys) || trim($keys)==<span class="string">''</span>)&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span>(!isset($type) || $type==<span class="string">''</span> || !in_array(strtolower($type),array(<span class="string">'asc'</span>,<span class="string">'desc'</span>)))&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	$keysvalue=array();</span><br><span class="line">	foreach($array <span class="keyword">as</span> $key=&gt;$val)&#123;</span><br><span class="line">		$val[$keys] = str_replace(<span class="string">'-'</span>,<span class="string">''</span>,$val[$keys]);</span><br><span class="line">		$val[$keys] = str_replace(<span class="string">' '</span>,<span class="string">''</span>,$val[$keys]);</span><br><span class="line">		$val[$keys] = str_replace(<span class="string">':'</span>,<span class="string">''</span>,$val[$keys]);</span><br><span class="line">		$keysvalue[] =$val[$keys];</span><br><span class="line">	&#125;</span><br><span class="line">	asort($keysvalue); <span class="comment">//key值排序</span></span><br><span class="line">	reset($keysvalue); <span class="comment">//指针重新指向数组第一个</span></span><br><span class="line">	foreach($keysvalue <span class="keyword">as</span> $key=&gt;$vals) &#123;</span><br><span class="line">		$keysort[] = $key;</span><br><span class="line">	&#125;</span><br><span class="line">	$keysvalue = array();</span><br><span class="line">	$count=count($keysort);</span><br><span class="line">	<span class="keyword">if</span>(strtolower($type) != <span class="string">'asc'</span>)&#123;</span><br><span class="line">		<span class="keyword">for</span>($i=$count<span class="number">-1</span>; $i&gt;=<span class="number">0</span>; $i--) &#123;</span><br><span class="line">			$keysvalue[] = $array[$keysort[$i]];</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">		<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;$count; $i++)&#123;</span><br><span class="line">			$keysvalue[] = $array[$keysort[$i]];</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> $keysvalue;</span><br><span class="line">&#125;</span><br><span class="line">$array=array(</span><br><span class="line">	<span class="number">0</span>=&gt;array(<span class="string">'id'</span>=&gt;<span class="number">8</span>,<span class="string">'username'</span>=&gt;<span class="string">'phpernote'</span>),</span><br><span class="line">	<span class="number">1</span>=&gt;array(<span class="string">'id'</span>=&gt;<span class="number">9</span>,<span class="string">'username'</span>=&gt;<span class="string">'com'</span>),</span><br><span class="line">	<span class="number">2</span>=&gt;array(<span class="string">'id'</span>=&gt;<span class="number">5</span>,<span class="string">'username'</span>=&gt;<span class="string">'www'</span>)</span><br><span class="line">);</span><br><span class="line">array_sort($array,<span class="string">'id'</span>,<span class="string">'asc'</span>);</span><br><span class="line">$trans = array (<span class="string">"a"</span> =&gt; <span class="number">1</span>, <span class="string">"b"</span> =&gt; <span class="number">1</span>, <span class="string">"c"</span> =&gt; <span class="number">2</span>);</span><br><span class="line">$trans = array_flip (array_flip($trans));</span><br><span class="line">print_r($trans);</span><br><span class="line">$arr = array( </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">1</span>,<span class="string">'name'</span> =&gt; <span class="string">'aaa'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">2</span>,<span class="string">'name'</span> =&gt; <span class="string">'bbb'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">3</span>,<span class="string">'name'</span> =&gt; <span class="string">'ccc'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">4</span>,<span class="string">'name'</span> =&gt; <span class="string">'ddd'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">5</span>,<span class="string">'name'</span> =&gt; <span class="string">'ccc'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">6</span>,<span class="string">'name'</span> =&gt; <span class="string">'aaa'</span>), </span><br><span class="line">array(<span class="string">'id'</span> =&gt; <span class="number">7</span>,<span class="string">'name'</span> =&gt; <span class="string">'bbb'</span>), </span><br><span class="line">); </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">assoc_unique</span>(<span class="params">&amp;$arr, $key</span>) </span></span><br><span class="line"><span class="function"></span>&#123; </span><br><span class="line">$rAr=array(); </span><br><span class="line"><span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;count($arr);$i++) </span><br><span class="line">&#123; </span><br><span class="line"><span class="keyword">if</span>(!isset($rAr[$arr[$i][$key]])) </span><br><span class="line">&#123; </span><br><span class="line">$rAr[$arr[$i][$key]]=$arr[$i]; </span><br><span class="line">&#125; </span><br><span class="line">&#125; </span><br><span class="line">$arr=array_values($rAr); </span><br><span class="line">&#125; </span><br><span class="line">assoc_unique($arr,<span class="string">'name'</span>); </span><br><span class="line">print_r($arr); </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_sort</span>(<span class="params">$arr,$keys,$type=<span class="string">'asc'</span></span>)</span>&#123; </span><br><span class="line">$keysvalue= $new_array= array(); </span><br><span class="line">foreach(<span class="function"><span class="params">$arras$k</span>=&gt;</span>$v)&#123; </span><br><span class="line">$keysvalue[$k] = $v[$keys]; </span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">if</span>($type== <span class="string">'asc'</span>)&#123; </span><br><span class="line">asort($keysvalue); </span><br><span class="line">&#125;<span class="keyword">else</span>&#123; </span><br><span class="line">arsort($keysvalue); </span><br><span class="line">&#125; </span><br><span class="line">reset($keysvalue); </span><br><span class="line">foreach(<span class="function"><span class="params">$keysvalueas$k</span>=&gt;</span>$v)&#123; </span><br><span class="line">$new_array[$k] = $arr[$k]; </span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">return</span>$new_array; </span><br><span class="line">&#125; </span><br><span class="line">$newArray= array_sort($array,<span class="string">'price'</span>); </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">hasort</span>(<span class="params">$arr</span>) </span>&#123;</span><br><span class="line">    $a = $b = array();</span><br><span class="line">    foreach($arr <span class="keyword">as</span> $v =&gt; $k) $a[$k][] = $v;</span><br><span class="line">    ksort($a);</span><br><span class="line">    print_r($a);</span><br><span class="line">    foreach($a <span class="keyword">as</span> $v =&gt; $i) </span><br><span class="line">        foreach($i <span class="keyword">as</span> $k) $b[$k] = $v;</span><br><span class="line">    <span class="keyword">return</span> $b;</span><br><span class="line">&#125;</span><br><span class="line">$a = array(<span class="string">'a'</span> =&gt; <span class="number">10</span>, <span class="string">'z'</span> =&gt; <span class="number">10</span>, <span class="string">'c'</span> =&gt; <span class="number">10</span>, <span class="string">'b'</span> =&gt; <span class="number">11</span>, <span class="string">'d'</span> =&gt; <span class="number">10</span>);</span><br><span class="line">$a = hasort($a);</span><br><span class="line">print_r($a);</span><br><span class="line">$a = array(<span class="string">'a'</span> =&gt; <span class="number">10</span>, <span class="string">'z'</span> =&gt; <span class="number">10</span>, <span class="string">'c'</span> =&gt; <span class="number">10</span>, <span class="string">'b'</span> =&gt; <span class="number">11</span>, <span class="string">'d'</span> =&gt; <span class="number">10</span>);</span><br><span class="line">asort($a, SORT_NUMERIC);</span><br><span class="line"><span class="comment">/**  </span></span><br><span class="line"><span class="comment"> * @param array $weight 权重  例如array('a'=&gt;10,'b'=&gt;20,'c'=&gt;50)  </span></span><br><span class="line"><span class="comment"> * @return string key   键名   </span></span><br><span class="line"><span class="comment"> */</span>  </span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">roll</span>(<span class="params">$weight = array(</span>)) </span>&#123;   </span><br><span class="line"> $roll = rand ( <span class="number">1</span>, array_sum ( $weight ) );   </span><br><span class="line"> $_tmpW = <span class="number">0</span>;   </span><br><span class="line"> $rollnum = <span class="number">0</span>;   </span><br><span class="line">  foreach ( $weight <span class="keyword">as</span> $k =&gt; $v ) &#123;   </span><br><span class="line">  $min = $_tmpW;   </span><br><span class="line">   $_tmpW += $v;   </span><br><span class="line">   $max = $_tmpW;   </span><br><span class="line">   <span class="keyword">if</span> ($roll &gt; $min &amp;&amp; $roll &lt;= $max) &#123;   </span><br><span class="line">    $rollnum = $k;   </span><br><span class="line">    <span class="keyword">break</span>;   </span><br><span class="line">   &#125;   </span><br><span class="line"> &#125;   </span><br><span class="line">  <span class="keyword">return</span> $rollnum;   </span><br><span class="line">&#125;   </span><br><span class="line"> </span><br><span class="line">$row=roll(array(<span class="string">'a'</span>=&gt;<span class="number">10</span>,<span class="string">'b'</span>=&gt;<span class="number">20</span>,<span class="string">'c'</span>=&gt;<span class="number">50</span>));   </span><br><span class="line">echo $row;   </span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">utf8_array_asort</span>(<span class="params">&amp;$array</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">if</span>(!isset($array) || !is_array($array)) &#123;</span><br><span class="line">   <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  foreach($array <span class="keyword">as</span> $k=&gt;$v) &#123;</span><br><span class="line">   $array[$k] = iconv(<span class="string">'UTF-8'</span>, <span class="string">'GBK//IGNORE'</span>,$v);</span><br><span class="line">  &#125;</span><br><span class="line">  asort($array);</span><br><span class="line">  foreach($array <span class="keyword">as</span> $k=&gt;$v) &#123;</span><br><span class="line">   $array[$k] = iconv(<span class="string">'GBK'</span>, <span class="string">'UTF-8//IGNORE'</span>, $v);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line">$abc = array(<span class="string">'a'</span>=&gt;<span class="string">'猜'</span>, <span class="string">'b'</span>=&gt;<span class="string">'我'</span>,<span class="string">'c'</span>=&gt;<span class="string">'哦'</span>,<span class="string">'d'</span>=&gt;<span class="string">'棍'</span>,<span class="string">'e'</span>=&gt;<span class="string">'f'</span>,<span class="string">'f'</span>=&gt;<span class="string">'爸'</span>,<span class="string">'z'</span>=&gt;<span class="string">'州'</span>);</span><br><span class="line">utf8_array_asort($abc);</span><br><span class="line">print_r($abc);</span><br></pre></td></tr></table></figure>
<h3 id="报错"><a href="#报错" class="headerlink" title="报错"></a>报错</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">PHP 里这样不会报错：&lt;?php var_dump(NoFound::<span class="class"><span class="keyword">class</span>)</span>; ?&gt;，不注意的话可能会掉坑。 ​​​​</span><br><span class="line"></span><br><span class="line">还有 http:<span class="comment">//xxx</span></span><br><span class="line"></span><br><span class="line">preg_match_all(<span class="string">'@\p&#123;Han&#125;@u'</span>,<span class="string">'微博'</span>,$m);这也能匹配汉字</span><br></pre></td></tr></table></figure>
<h3 id="并发场景下的重复插入"><a href="#并发场景下的重复插入" class="headerlink" title="并发场景下的重复插入"></a>并发场景下的重复插入</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">$lock = Cache::lock(<span class="string">'key'</span>, <span class="number">60</span>);</span><br><span class="line">abort_if(!$lock-&gt;get(), <span class="number">422</span>, <span class="string">'操作过于频繁，请稍后再试！'</span>);</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">$lock-&gt;release();</span><br><span class="line">一个用户只能一条吗？用 redis 集合，把用户 id 扔集合里，返回已存在的，就证明已插过了。扔成功的，就是没插入过的。</span><br><span class="line">$lock-&gt;block(<span class="number">3</span>,<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="comment">// todo</span></span><br><span class="line">    <span class="comment">// 在这闭包下写业务逻辑，并且不用手动释放锁，框架会为你自动释放，感觉方便些</span></span><br><span class="line">&#125;);</span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/34295</span></span><br></pre></td></tr></table></figure>
<h3 id="小数点-00"><a href="#小数点-00" class="headerlink" title="小数点 00"></a>小数点 00</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">$num = [</span><br><span class="line">    <span class="string">"a"</span> =&gt; <span class="number">20.00</span>,</span><br><span class="line">    <span class="string">"b"</span> =&gt; <span class="number">39.78</span>,</span><br><span class="line">];</span><br><span class="line">echo json_encode($num);</span><br><span class="line"><span class="comment">// &#123;"a":20,"b":39.78&#125;</span></span><br><span class="line">echo <span class="number">66.00</span>;</span><br><span class="line"><span class="comment">// 66</span></span><br><span class="line">$num = sprintf(<span class="string">"%1\$.2f"</span>, <span class="number">66.00</span>);</span><br><span class="line">var_dump($num);</span><br><span class="line"><span class="comment">// string(4) "66.00"</span></span><br><span class="line">或者</span><br><span class="line"></span><br><span class="line">$num = number_format(<span class="number">66.00</span>,<span class="number">2</span>,<span class="string">'.'</span>,<span class="string">''</span>);</span><br><span class="line">var_dump($num);</span><br><span class="line"><span class="comment">// string(5) "66.00"</span></span><br><span class="line"></span><br><span class="line">$output = array(<span class="string">'x'</span> =&gt; <span class="string">'y'</span>, <span class="string">'price'</span> =&gt; <span class="string">'30.00'</span>);</span><br><span class="line">$json = json_encode($output);</span><br><span class="line">$json = str_replace(<span class="string">'"price":"'</span>.$output[<span class="string">'price'</span>].<span class="string">'"'</span>, <span class="string">'"price":'</span>.$output[<span class="string">'price'</span>].<span class="string">''</span>, $json);</span><br><span class="line">print $json;</span><br><span class="line"><span class="comment">// &#123;"x":"y","price":30.00&#125;</span></span><br><span class="line"></span><br><span class="line">https:<span class="comment">//laravelcode.cn/posts/104/a-brief-talk-on-the-return-value-of-the-decimal-point-00-of-the-output-functions-of-various-languages</span></span><br></pre></td></tr></table></figure>
<h3 id="反射之动态代理"><a href="#反射之动态代理" class="headerlink" title="反射之动态代理"></a>反射之动态代理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">基于动态代理，可以有更多的想象空间，如实现拦截器，属性方法增加，裁剪等等</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Mysql</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">connect</span>(<span class="params">$db</span>)</span>&#123;</span><br><span class="line">         echo <span class="string">"connecting database $&#123;db[0]&#125;\r\n"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SqlProxy</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    private $target;</span><br><span class="line">     <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$tar</span>)</span>&#123;</span><br><span class="line">         $<span class="keyword">this</span>-&gt;target[]  = <span class="keyword">new</span> $tar();</span><br><span class="line">     &#125;</span><br><span class="line"></span><br><span class="line">     <span class="function"><span class="keyword">function</span> <span class="title">__call</span>(<span class="params">$name, $args</span>)</span>&#123;</span><br><span class="line">             <span class="keyword">if</span>($method = $r-&gt;getMethod($name))&#123;</span><br><span class="line">                 <span class="keyword">if</span>($method-&gt;isPublic() &amp;&amp; !$method-&gt;isAbstract())&#123;</span><br><span class="line">                     echo <span class="string">"method before record \r\n"</span>;</span><br><span class="line">                     $method-&gt;invoke($obj,$args);</span><br><span class="line">                     echo <span class="string">"method after record\r\n"</span>;</span><br><span class="line">                 &#125;</span><br><span class="line">             &#125;</span><br><span class="line">         &#125;</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> $obj = <span class="keyword">new</span> SqlProxy(<span class="string">'Mysql'</span>);</span><br><span class="line"> $obj-&gt;connect(<span class="string">'member'</span>);</span><br><span class="line"> https:<span class="comment">//learnku.com/articles/34288</span></span><br><span class="line">反射可以探知类的内部结构 可以用它做 hook 实现插件功能，或者做动态代理</span><br></pre></td></tr></table></figure>
<h3 id="PhpSpreadsheet-导出图片到-Excel"><a href="#PhpSpreadsheet-导出图片到-Excel" class="headerlink" title="PhpSpreadsheet 导出图片到 Excel"></a>PhpSpreadsheet 导出图片到 Excel</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"> public <span class="function"><span class="keyword">function</span> <span class="title">export</span>(<span class="params">$data</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $spreadsheet = <span class="keyword">new</span> Spreadsheet();</span><br><span class="line">        $sheet = $spreadsheet-&gt;getActiveSheet();</span><br><span class="line">        <span class="comment">//设置sheet的名字  两种方法</span></span><br><span class="line">        $sheet-&gt;setTitle(<span class="string">'phpspreadsheet——demo'</span>);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;setTitle(<span class="string">'Hello'</span>);</span><br><span class="line">        <span class="comment">//设置第一行小标题</span></span><br><span class="line">        $k = <span class="number">1</span>;</span><br><span class="line">        $sheet-&gt;setCellValue(<span class="string">'A'</span> . $k, <span class="string">'问题'</span>);</span><br><span class="line">        $sheet-&gt;setCellValue(<span class="string">'B'</span> . $k, <span class="string">'选项'</span>);</span><br><span class="line">        $sheet-&gt;setCellValue(<span class="string">'C'</span> . $k, <span class="string">'答案'</span>);</span><br><span class="line">        $sheet-&gt;setCellValue(<span class="string">'D'</span> . $k, <span class="string">'图片'</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 设置个表格宽度</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension(<span class="string">'A'</span>)-&gt;setWidth(<span class="number">16</span>);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension(<span class="string">'B'</span>)-&gt;setWidth(<span class="number">80</span>);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension(<span class="string">'C'</span>)-&gt;setWidth(<span class="number">15</span>);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension(<span class="string">'D'</span>)-&gt;setWidth(<span class="number">20</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 垂直居中</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getStyle(<span class="string">'A'</span>)-&gt;getAlignment()-&gt;setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getStyle(<span class="string">'B'</span>)-&gt;getAlignment()-&gt;setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getStyle(<span class="string">'C'</span>)-&gt;getAlignment()-&gt;setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);</span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getStyle(<span class="string">'D'</span>)-&gt;getAlignment()-&gt;setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);</span><br><span class="line"></span><br><span class="line">        $info = $data;</span><br><span class="line">        <span class="comment">//  设置A单元格的宽度 同理设置每个</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getColumnDimension(<span class="string">'A'</span>)-&gt;setWidth(<span class="number">20</span>);</span><br><span class="line">        <span class="comment">//  设置第三行的高度</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;getRowDimension(<span class="string">'3'</span>)-&gt;setRowHeight(<span class="number">50</span>);</span><br><span class="line">        <span class="comment">//  A1水平居中</span></span><br><span class="line">        $styleArray = [</span><br><span class="line">            <span class="string">'alignment'</span> =&gt; [</span><br><span class="line">                <span class="string">'horizontal'</span> =&gt; \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,</span><br><span class="line">            ],</span><br><span class="line">        ];</span><br><span class="line">        $sheet-&gt;getStyle(<span class="string">'A1'</span>)-&gt;applyFromArray($styleArray);</span><br><span class="line">        <span class="comment">//  将A3到D4合并成一个单元格</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;mergeCells(<span class="string">'A3:D4'</span>);</span><br><span class="line">        <span class="comment">//  拆分合并单元格</span></span><br><span class="line">        $spreadsheet-&gt;getActiveSheet()-&gt;unmergeCells(<span class="string">'A3:D4'</span>);</span><br><span class="line">        <span class="comment">//  将A2到D8表格边框 改变为红色</span></span><br><span class="line">        $styleArray = [</span><br><span class="line">            <span class="string">'borders'</span> =&gt; [</span><br><span class="line">                <span class="string">'outline'</span> =&gt; [</span><br><span class="line">                    <span class="string">'borderStyle'</span> =&gt; \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,</span><br><span class="line">                    <span class="string">'color'</span> =&gt; [<span class="string">'argb'</span> =&gt; <span class="string">'FFFF0000'</span>],</span><br><span class="line">                ],</span><br><span class="line">            ],</span><br><span class="line">        ];</span><br><span class="line">        <span class="comment">//  $sheet-&gt;getStyle('A2:E8')-&gt;applyFromArray($styleArray);</span></span><br><span class="line">        <span class="comment">//  设置超链接</span></span><br><span class="line">        <span class="comment">//  $sheet-&gt;setCellValue('D6', 'www.baidu.com');</span></span><br><span class="line">        <span class="comment">//  $spreadsheet-&gt;getActiveSheet()-&gt;setCellValue('E6', 'www.baidu.com');</span></span><br><span class="line">        <span class="comment">//  循环赋值</span></span><br><span class="line">        $k = <span class="number">2</span>;</span><br><span class="line">        foreach ($info <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">            $sheet-&gt;setCellValue(<span class="string">'A'</span> . $k, $value[<span class="string">'question'</span>]);</span><br><span class="line">            $sheet-&gt;setCellValue(<span class="string">'B'</span> . $k, $value[<span class="string">'question_options'</span>]);</span><br><span class="line">            $sheet-&gt;setCellValue(<span class="string">'C'</span> . $k, $value[<span class="string">'answer'</span>]);</span><br><span class="line"></span><br><span class="line">            $img = self::curlGet($value[<span class="string">'img'</span>]);</span><br><span class="line">            $dir = public_path(<span class="string">'/temp/image/'</span>);</span><br><span class="line">            $file_info = pathinfo($value[<span class="string">'img'</span>]);</span><br><span class="line">            <span class="keyword">if</span> (!empty($file_info[<span class="string">'basename'</span>])) &#123; <span class="comment">//过滤非文件类型</span></span><br><span class="line">                $basename = $file_info[<span class="string">'basename'</span>];</span><br><span class="line">                is_dir($dir) OR mkdir($dir, <span class="number">0777</span>, <span class="literal">true</span>); <span class="comment">//进行检测文件是否存在</span></span><br><span class="line">                file_put_contents($dir . $basename, $img);</span><br><span class="line"></span><br><span class="line">                $drawing[$k] = <span class="keyword">new</span> Drawing();</span><br><span class="line">                $drawing[$k]-&gt;setName(<span class="string">'Logo'</span>);</span><br><span class="line">                $drawing[$k]-&gt;setDescription(<span class="string">'Logo'</span>);</span><br><span class="line">                $drawing[$k]-&gt;setPath($dir . $basename);</span><br><span class="line">                $drawing[$k]-&gt;setWidth(<span class="number">80</span>);</span><br><span class="line">                $drawing[$k]-&gt;setHeight(<span class="number">80</span>);</span><br><span class="line">                $drawing[$k]-&gt;setCoordinates(<span class="string">'D'</span>.$k);</span><br><span class="line">                $drawing[$k]-&gt;setOffsetX(<span class="number">12</span>);</span><br><span class="line">                $drawing[$k]-&gt;setOffsetY(<span class="number">12</span>);</span><br><span class="line">                $drawing[$k]-&gt;setWorksheet($spreadsheet-&gt;getActiveSheet());</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                $sheet-&gt;setCellValue(<span class="string">'D'</span> . $k, <span class="string">''</span>);</span><br><span class="line">            &#125;</span><br><span class="line">            $sheet-&gt;getRowDimension($k)-&gt;setRowHeight(<span class="number">80</span>);</span><br><span class="line">            $k++;</span><br><span class="line">        &#125;</span><br><span class="line">        $file_name = date(<span class="string">'Y-m-d'</span>, time()) . rand(<span class="number">1000</span>, <span class="number">9999</span>);</span><br><span class="line">        <span class="comment">//  第一种保存方式</span></span><br><span class="line">        <span class="comment">/*$writer = new Xlsx($spreadsheet);</span></span><br><span class="line"><span class="comment">        //保存的路径可自行设置</span></span><br><span class="line"><span class="comment">        $file_name = '../'.$file_name . ".xlsx";</span></span><br><span class="line"><span class="comment">        $writer-&gt;save($file_name);*/</span></span><br><span class="line">        <span class="comment">//  第二种直接页面上显示下载</span></span><br><span class="line">        $file_name = $file_name . <span class="string">".xls"</span>;</span><br><span class="line">        header(<span class="string">'Content-Type: application/vnd.ms-excel'</span>);</span><br><span class="line">        header(<span class="string">'Content-Disposition: attachment;filename="'</span> . $file_name . <span class="string">'"'</span>);</span><br><span class="line">        header(<span class="string">'Cache-Control: max-age=0'</span>);</span><br><span class="line">        $writer = IOFactory::createWriter($spreadsheet, <span class="string">'Xls'</span>);</span><br><span class="line">        <span class="comment">//  注意createWriter($spreadsheet, 'Xls') 第二个参数首字母必须大写</span></span><br><span class="line">        $writer-&gt;save(<span class="string">'php://output'</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getClient</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        $client = <span class="keyword">new</span> Client();</span><br><span class="line">        <span class="keyword">return</span> $client;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">curlGet</span>(<span class="params">$url</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $ch = curl_init();</span><br><span class="line">        curl_setopt($ch, CURLOPT_URL, $url);</span><br><span class="line">        curl_setopt($ch, CURLOPT_HEADER, <span class="number">0</span>);</span><br><span class="line">        curl_setopt($ch, CURLOPT_RETURNTRANSFER, <span class="number">1</span>);</span><br><span class="line">        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, <span class="literal">false</span>); <span class="comment">// 这个是重点 请求https。</span></span><br><span class="line">        $data = curl_exec($ch);</span><br><span class="line">        curl_close($ch);</span><br><span class="line">        <span class="keyword">return</span> $data;</span><br><span class="line">    &#125;</span><br><span class="line">    https:<span class="comment">//learnku.com/articles/26965</span></span><br><span class="line">在其他地方调用 <span class="keyword">export</span> 方法，传入 $data 数组，数组中有四个字段：question,question_options,answer,img ，其中 img 就是图片的远程地址，剩下的再看一下代码</span><br></pre></td></tr></table></figure>
<h3 id="PHP-多进程开发"><a href="#PHP-多进程开发" class="headerlink" title="PHP 多进程开发"></a>PHP 多进程开发</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">include __DIR__ . <span class="string">'/vendor/autoload.php'</span>;<span class="comment">//引入自动加载类</span></span><br><span class="line"></span><br><span class="line">use Goutte\Client;<span class="comment">//使用第三方采集库</span></span><br><span class="line"></span><br><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line"></span><br><span class="line">$links = [</span><br><span class="line">    <span class="string">'http://www.nipic.com/topic/show_27192_1.html'</span>,</span><br><span class="line">    <span class="string">'http://www.nipic.com/topic/show_27054_1.html'</span>,</span><br><span class="line">    <span class="string">'http://www.nipic.com/topic/show_27085_1.html'</span>,</span><br><span class="line">];<span class="comment">//要爬的三个分类下的图片</span></span><br><span class="line"></span><br><span class="line">$pids = [];<span class="comment">//定义一个子进程的数组</span></span><br><span class="line"></span><br><span class="line">foreach ($links <span class="keyword">as</span> $url) &#123;</span><br><span class="line">    $pid = pcntl_fork();<span class="comment">//fork 一个子进程</span></span><br><span class="line">    <span class="keyword">switch</span> ($pid) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">-1</span>:</span><br><span class="line">        die(<span class="string">"Fork failed\n"</span>);</span><br><span class="line">    <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line"></span><br><span class="line">        $id = posix_getpid();<span class="comment">//得到子进程id</span></span><br><span class="line">        $pids[$id] = $id;<span class="comment">//存入到子进程数组id 中</span></span><br><span class="line">        $data = [];</span><br><span class="line"></span><br><span class="line">        $crawler = $client-&gt;request(<span class="string">'GET'</span>, $url);</span><br><span class="line">        $crawler-&gt;filter(<span class="string">'.search-works-thumb'</span>)-&gt;each(<span class="function"><span class="keyword">function</span>(<span class="params">$node</span>) <span class="title">use</span> (<span class="params">$client, $id, &amp;$data</span>) </span>&#123;</span><br><span class="line">            $url = $node-&gt;link()-&gt;getUri();</span><br><span class="line"></span><br><span class="line">            $crawler = $client-&gt;request(<span class="string">'GET'</span>, $url);</span><br><span class="line">            $crawler-&gt;filter(<span class="string">'#J_worksImg'</span>)-&gt;each(<span class="function"><span class="keyword">function</span>(<span class="params">$node</span>) <span class="title">use</span> (<span class="params">$id, &amp;$data</span>) </span>&#123;</span><br><span class="line">                $src = $node-&gt;image()-&gt;getUri();</span><br><span class="line"></span><br><span class="line">                $data[$id][] = $src;<span class="comment">//存入消息队列 或者redis 都可以</span></span><br><span class="line">                <span class="comment">//echo $src . PHP_EOL;</span></span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        print_r($data);</span><br><span class="line"></span><br><span class="line">        exit;<span class="comment">//结束子进程</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    <span class="keyword">default</span>:</span><br><span class="line">        sleep(<span class="number">2</span>);</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> ( count($pids) ) &#123;</span><br><span class="line">    <span class="keyword">if</span> (($id = pcntl_wait($status, WUNTRACED)) &gt; <span class="number">0</span>) &#123;<span class="comment">//主进程 阻塞等待子进程完成任务</span></span><br><span class="line">        unset($pids[$id]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/26756</span></span><br></pre></td></tr></table></figure>
<h3 id="larvel-excel"><a href="#larvel-excel" class="headerlink" title="larvel excel"></a>larvel excel</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">drawings</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//这里的数据自己组装</span></span><br><span class="line">    $draw_arr = [<span class="number">1</span> =&gt;<span class="string">'detail1.jpg'</span>, <span class="number">2</span> =&gt; <span class="string">'detail2.jpg'</span>];</span><br><span class="line">    $result = [];</span><br><span class="line">    foreach ($draw_arr <span class="keyword">as</span> $k =&gt; $v) &#123;</span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125; = <span class="keyword">new</span> Drawing();<span class="comment">//变量还能这样用</span></span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125;-&gt;setName(<span class="string">'Other image'</span>);</span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125;-&gt;setDescription(<span class="string">'This is a second image'</span>);</span><br><span class="line">      <span class="comment">//图片路径</span></span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125;-&gt;setPath(public_path($v));</span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125;-&gt;setHeight(<span class="number">50</span>);</span><br><span class="line">      <span class="comment">//设置图片列</span></span><br><span class="line">      $&#123;<span class="string">'drawing'</span>.$k&#125;-&gt;setCoordinates(<span class="string">'U'</span>.$k);</span><br><span class="line">      $result[] = $&#123;<span class="string">'drawing'</span>.$k&#125;;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $result;</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/32391</span></span><br></pre></td></tr></table></figure>
<h3 id="权重随机算法"><a href="#权重随机算法" class="headerlink" title="权重随机算法"></a>权重随机算法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">WeightedRoundRobin</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    private <span class="keyword">static</span> $_weightArray = array();</span><br><span class="line"></span><br><span class="line">    private <span class="keyword">static</span> $_i = <span class="number">-1</span>;<span class="comment">//代表上一次选择的服务器</span></span><br><span class="line">    private <span class="keyword">static</span> $_gcd;<span class="comment">//表示集合S中所有服务器权值的最大公约数</span></span><br><span class="line">    private <span class="keyword">static</span> $_cw = <span class="number">0</span>;<span class="comment">//当前调度的权值</span></span><br><span class="line">    private <span class="keyword">static</span> $_max;</span><br><span class="line">    private <span class="keyword">static</span> $_n;<span class="comment">//agent个数</span></span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">init</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">initParam</span>(<span class="params">array $weightArray</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        self::$_weightArray = $weightArray;</span><br><span class="line">        self::$_gcd = self::getGcd(self::$_weightArray);</span><br><span class="line">        self::$_max = self::getMaxWeight(self::$_weightArray);</span><br><span class="line">        self::$_n = count($weightArray);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">getGcd</span>(<span class="params">array $weightArray</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $temp = array_shift($weightArray);</span><br><span class="line">        $min = $temp[<span class="string">'weight'</span>];</span><br><span class="line">        $status = <span class="literal">false</span>;</span><br><span class="line">        foreach ($weightArray <span class="keyword">as</span> $val) &#123;</span><br><span class="line">            $min = min($val[<span class="string">'weight'</span>],$min);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span>($min == <span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">for</span> ($i = $min; $i&gt;<span class="number">1</span>; $i--) &#123;</span><br><span class="line"></span><br><span class="line">                foreach ($weightArray <span class="keyword">as</span> $val) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (is_int($val[<span class="string">'weight'</span>]/$i)) &#123;</span><br><span class="line">                        $status = <span class="literal">true</span>;</span><br><span class="line">                    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                        $status = <span class="literal">false</span>;</span><br><span class="line">                        <span class="keyword">break</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> ($status) &#123;</span><br><span class="line">                    <span class="keyword">return</span> $i;</span><br><span class="line">                &#125;<span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    private <span class="keyword">static</span>  <span class="function"><span class="keyword">function</span> <span class="title">getMaxWeight</span>(<span class="params">array $weightArray</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(empty($weightArray))&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $temp = array_shift($weightArray);</span><br><span class="line">        $max = $temp[<span class="string">'weight'</span>];</span><br><span class="line">        foreach ($weightArray <span class="keyword">as</span> $val) &#123;</span><br><span class="line">            $max = max($val[<span class="string">'weight'</span>],$max);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $max;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getWeight</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">while</span> (<span class="literal">true</span>)&#123;</span><br><span class="line"></span><br><span class="line">            self::$_i = ((int)self::$_i+<span class="number">1</span>) % (int)self::$_n;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> (self::$_i == <span class="number">0</span>) &#123;</span><br><span class="line"></span><br><span class="line">                self::$_cw = (int)self::$_cw - (int)self::$_gcd;</span><br><span class="line">                <span class="keyword">if</span> (self::$_cw &lt;= <span class="number">0</span>) &#123;</span><br><span class="line">                    self::$_cw = (int)self::$_max;</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">if</span> (self::$_cw == <span class="number">0</span>) &#123;</span><br><span class="line">                        <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> ((int)(self::$_weightArray[self::$_i][<span class="string">'weight'</span>]) &gt;= self::$_cw) &#123;</span><br><span class="line">                <span class="keyword">return</span> self::$_weightArray[self::$_i][<span class="string">'id'</span>];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/34449</span></span><br></pre></td></tr></table></figure>
<h3 id="base64原理"><a href="#base64原理" class="headerlink" title="base64原理"></a>base64原理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">数据先做一个 Base64 编码，统统变成可见字符，降低错误率。基于 A-Z、a-z、<span class="number">0</span><span class="number">-9</span> 以及 <span class="string">'+'</span> 和 <span class="string">'/'</span> 共 <span class="number">64</span> 个字符的编码方式，因为 <span class="number">2</span> 的 <span class="number">6</span> 次方等于 <span class="number">64</span>，所以说只需要 <span class="number">6</span> 个比特即可表示一个 base64 的字符。</span><br><span class="line">                                </span><br><span class="line">                                编码表：<span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span></span><br><span class="line">                                核心原理是将二进制数据进行分组，以 <span class="number">6</span> 位一组进行分组，并在每组前面都填两个高位 <span class="number">0</span>，然后将 <span class="number">8</span> bit 的字节转换成十进制，对照 BASE64 编码表 （上表），得到对应编码后的字符。</span><br><span class="line">以对<span class="number">6666</span>P进行base64编码的步骤说明</span><br><span class="line">每个字符转化为<span class="number">8</span>bit：</span><br><span class="line"><span class="number">6</span>-----&gt;<span class="number">00110110</span></span><br><span class="line"><span class="number">6</span>-----&gt;<span class="number">00110110</span></span><br><span class="line"><span class="number">6</span>-----&gt;<span class="number">00110110</span></span><br><span class="line"><span class="number">6</span>-----&gt;<span class="number">00110110</span></span><br><span class="line">P-----&gt;<span class="number">01010000</span></span><br><span class="line">补位-----&gt;<span class="number">00000000</span></span><br><span class="line">整体拼接结果：</span><br><span class="line"><span class="number">001101100011011000110110001101100101000000000000</span></span><br><span class="line">以<span class="number">6</span>bit一组进行分割：</span><br><span class="line"><span class="number">001101</span>  <span class="number">100011</span>  <span class="number">011000</span>  <span class="number">110110</span>  <span class="number">001101</span>  <span class="number">100101</span>  <span class="number">000000</span>  <span class="number">000000</span></span><br><span class="line">转化为base64编码脚标：</span><br><span class="line"><span class="number">13</span>  <span class="number">35</span>  <span class="number">24</span>  <span class="number">54</span>  <span class="number">13</span>  <span class="number">37</span>  <span class="number">0</span>  <span class="number">0</span></span><br><span class="line">获取对应的base64编码：</span><br><span class="line">N  j  Y  <span class="number">2</span>  N  l  A  A</span><br><span class="line">得到结果：string(<span class="number">8</span>) <span class="string">"NjY2NlA="</span></span><br><span class="line"></span><br><span class="line">$a = <span class="string">"6666P"</span>;</span><br><span class="line"></span><br><span class="line">$decbinStr= <span class="string">''</span>;</span><br><span class="line"><span class="comment">//计算补位</span></span><br><span class="line">$end = (<span class="number">3</span> - strlen($a)%<span class="number">3</span>)%<span class="number">3</span>;</span><br><span class="line"><span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;strlen($a);$i++)&#123;</span><br><span class="line">    <span class="comment">//每个字符转化为8bit</span></span><br><span class="line">    $decbin = str_pad(decbin(ord($a[$i])),<span class="number">8</span>,<span class="string">"0"</span>,STR_PAD_LEFT);</span><br><span class="line">    $decbinStr .= $decbin ;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//增加补位</span></span><br><span class="line">$decbinStr = $decbinStr. str_pad(<span class="string">""</span>,$end*<span class="number">8</span>,<span class="string">"0"</span>);</span><br><span class="line"><span class="comment">//以6bit一组进行分割</span></span><br><span class="line">$arr = str_split($decbinStr,<span class="number">6</span>);</span><br><span class="line"><span class="comment">//转化成对应的base64编码</span></span><br><span class="line">$result = implode(<span class="string">""</span>, array_map(<span class="string">"getBase64Str"</span>,$arr));</span><br><span class="line"><span class="comment">//末尾补位的数据处理</span></span><br><span class="line"><span class="keyword">for</span>($j=<span class="number">0</span>;$j&lt;$end;$j++)&#123;</span><br><span class="line">    <span class="keyword">if</span>($result[strlen($result)<span class="number">-1</span>-$j] == <span class="string">'A'</span>)&#123;</span><br><span class="line">      $result[strlen($result)<span class="number">-1</span>-$j] = <span class="string">"="</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//验证下跟自带的base64_encode结果是否一致</span></span><br><span class="line">var_dump($result);</span><br><span class="line">var_dump(base64_encode($a));</span><br><span class="line"></span><br><span class="line">exit();</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getBase64Str</span>(<span class="params">$sixStr</span>)</span>&#123;</span><br><span class="line">    $number = bindec($sixStr);</span><br><span class="line">    $baseHash = <span class="string">'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'</span>;</span><br><span class="line">    <span class="keyword">return</span> $baseHash[$number];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/34439</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-内存溢出"><a href="#PHP-内存溢出" class="headerlink" title="PHP 内存溢出"></a>PHP 内存溢出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ExportService</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> $outPutFile = <span class="string">''</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出文件</span></span><br><span class="line"><span class="comment">     * @param string $fileName</span></span><br><span class="line"><span class="comment">     * @param $data</span></span><br><span class="line"><span class="comment">     * @param array $formFields</span></span><br><span class="line"><span class="comment">     * @return mixed</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">exportData</span>(<span class="params">$fileName = <span class="string">''</span>, $data, $formFields = []</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $fileArr = [];</span><br><span class="line">        $tmpPath = \Yii::$app-&gt;params[<span class="string">'excelSavePath'</span>];</span><br><span class="line"></span><br><span class="line">        foreach (array_chunk($data, <span class="number">10000</span>) <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">            self::$outPutFile = <span class="string">''</span>;</span><br><span class="line">            $subject          = !empty($fileName) ? $fileName : <span class="string">'data_'</span>;</span><br><span class="line">            $subject          .= date(<span class="string">'YmdHis'</span>);</span><br><span class="line">            <span class="keyword">if</span> (empty($value) || empty($formFields)) &#123;</span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            self::$outPutFile = $tmpPath . $subject . $key . <span class="string">'.csv'</span>;</span><br><span class="line">            <span class="keyword">if</span> (!file_exists(self::$outPutFile)) &#123;</span><br><span class="line">                touch(self::$outPutFile);</span><br><span class="line">            &#125;</span><br><span class="line">            $index  = array_keys($formFields);</span><br><span class="line">            $header = array_values($formFields);</span><br><span class="line">            self::outPut($header);</span><br><span class="line"></span><br><span class="line">            foreach ($value <span class="keyword">as</span> $k =&gt; $v) &#123;</span><br><span class="line">                $tmpData = [];</span><br><span class="line">                foreach ($index <span class="keyword">as</span> $item) &#123;</span><br><span class="line">                    $tmpData[] = isset($v[$item]) ? $v[$item] : <span class="string">''</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                self::outPut($tmpData);</span><br><span class="line">            &#125;</span><br><span class="line">            $fileArr[] = self::$outPutFile;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $zipFile = $tmpPath . $fileName . date(<span class="string">'YmdHi'</span>) . <span class="string">'.zip'</span>;</span><br><span class="line">        $zipRes = self::zipFile($fileArr, $zipFile);</span><br><span class="line">        <span class="keyword">return</span> $zipRes;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 向文件写入数据</span></span><br><span class="line"><span class="comment">     * @param array $data</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">outPut</span>(<span class="params">$data = []</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (is_array($data) &amp;&amp; !empty($data)) &#123;</span><br><span class="line">            $data = implode(<span class="string">','</span>, $data);</span><br><span class="line">            file_put_contents(self::$outPutFile, iconv(<span class="string">"UTF-8"</span>, <span class="string">"GB2312//IGNORE"</span>, $data) . PHP_EOL, FILE_APPEND);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 压缩文件</span></span><br><span class="line"><span class="comment">     * @param $sourceFile</span></span><br><span class="line"><span class="comment">     * @param $distFile</span></span><br><span class="line"><span class="comment">     * @return mixed</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">zipFile</span>(<span class="params">$sourceFile, $distFile</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $zip = <span class="keyword">new</span> \ZipArchive();</span><br><span class="line">        <span class="keyword">if</span> ($zip-&gt;open($distFile, \ZipArchive::CREATE) !== <span class="literal">true</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> $sourceFile;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $zip-&gt;open($distFile, \ZipArchive::CREATE);</span><br><span class="line">        foreach ($sourceFile <span class="keyword">as</span> $file) &#123;</span><br><span class="line">            $fileContent = file_get_contents($file);</span><br><span class="line">            $file        = iconv(<span class="string">'utf-8'</span>, <span class="string">'GBK'</span>, basename($file));</span><br><span class="line">            $zip-&gt;addFromString($file, $fileContent);</span><br><span class="line">        &#125;</span><br><span class="line">        $zip-&gt;close();</span><br><span class="line">        <span class="keyword">return</span> $distFile;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 下载文件</span></span><br><span class="line"><span class="comment">     * @param $filePath</span></span><br><span class="line"><span class="comment">     * @param $fileName</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">download</span>(<span class="params">$filePath, $fileName</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (!file_exists($filePath . $fileName)) &#123;</span><br><span class="line">            header(<span class="string">'HTTP/1.1 404 NOT FOUND'</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="comment">//以只读和二进制模式打开文件</span></span><br><span class="line">            $file = fopen($filePath . $fileName, <span class="string">"rb"</span>);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//告诉浏览器这是一个文件流格式的文件</span></span><br><span class="line">            Header(<span class="string">"Content-type: application/octet-stream"</span>);</span><br><span class="line">            <span class="comment">//请求范围的度量单位</span></span><br><span class="line">            Header(<span class="string">"Accept-Ranges: bytes"</span>);</span><br><span class="line">            <span class="comment">//Content-Length是指定包含于请求或响应中数据的字节长度</span></span><br><span class="line">            Header(<span class="string">"Accept-Length: "</span> . filesize($filePath . $fileName));</span><br><span class="line">            <span class="comment">//用来告诉浏览器，文件是可以当做附件被下载，下载后的文件名称为$file_name该变量的值</span></span><br><span class="line">            Header(<span class="string">"Content-Disposition: attachment; filename="</span> . $fileName);</span><br><span class="line"></span><br><span class="line">            <span class="comment">//读取文件内容并直接输出到浏览器</span></span><br><span class="line">            echo fread($file, filesize($filePath . $fileName));</span><br><span class="line">            fclose($file);</span><br><span class="line">            exit();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;           https:<span class="comment">//learnku.com/articles/34512</span></span><br></pre></td></tr></table></figure>
<h3 id="24-小时排行榜实时更新"><a href="#24-小时排行榜实时更新" class="headerlink" title="24 小时排行榜实时更新"></a>24 小时排行榜实时更新</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ZADD KEY_NAME SCORE1 VALUE1.. SCOREN VALUEN</span><br><span class="line">利用 ZADD 按小时划分添加用户的积分信息，然后用 ZUNIONSTORE 并集实现 <span class="number">24</span> 小时的游戏积分总和，实现 “<span class="number">24</span> 小时排行榜”</span><br><span class="line">Redis 在遇到分数相同时是按照集合成员自身的字典顺序来排序，这里即是按照”user2″和”user3″这两个字符串进行排序，以逆序排序的话 user3 自然排到了前面。要解决这个问题，我们可以考虑在分数中加入时间戳，计算公式为：</span><br><span class="line">带时间戳的分数 = 实际分数*<span class="number">10000000000</span> + (<span class="number">9999999999</span> – timestamp)</span><br><span class="line">   ZUNIONSTORE destination numkeys key [key ...]</span><br><span class="line">    Redis Zunionstore 命令计算给定的一个或多个有序集的并集，其中给定 key 的数量必须以 numkeys 参数指定，并     将该并集(结果集)储存到 destination 。</span><br><span class="line">    默认情况下，结果集中某个成员的分数值是所有给定集下该成员分数值之和 。</span><br><span class="line">https:<span class="comment">//learnku.com/articles/30279</span></span><br></pre></td></tr></table></figure>
<h3 id="数组操作"><a href="#数组操作" class="headerlink" title="数组操作"></a>数组操作</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 数组层级缩进转换</span></span><br><span class="line"><span class="comment"> * @param array $array 源数组</span></span><br><span class="line"><span class="comment"> * @param int   $pid</span></span><br><span class="line"><span class="comment"> * @param int   $level</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Array2level</span>(<span class="params">$array, $pid = <span class="number">0</span>, $level = <span class="number">1</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> $list = [];</span><br><span class="line">    foreach ($array <span class="keyword">as</span> $v) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($v[<span class="string">'pid'</span>] == $pid) &#123;</span><br><span class="line">            $v[<span class="string">'level'</span>] = $level;</span><br><span class="line">            $list[]     = $v;</span><br><span class="line">            Array2level($array, $v[<span class="string">'id'</span>], $level + <span class="number">1</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $list;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 把返回的数据集转换成Tree</span></span><br><span class="line"><span class="comment"> * @access public</span></span><br><span class="line"><span class="comment"> * @param array $list 要转换的数据集</span></span><br><span class="line"><span class="comment"> * @param string $pid parent标记字段</span></span><br><span class="line"><span class="comment"> * @param string $level level标记字段</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">list_to_tree</span>(<span class="params">$list, $pk=<span class="string">'id'</span>, $pid = <span class="string">'pid'</span>, $child = <span class="string">'son'</span>, $root = <span class="number">0</span>, $is_count = false</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 创建Tree</span></span><br><span class="line">    $tree = [];</span><br><span class="line">    <span class="keyword">if</span>(is_array($list)) &#123;</span><br><span class="line">        <span class="comment">// 创建基于主键的数组引用</span></span><br><span class="line">        $refer = [];</span><br><span class="line">        foreach ($list <span class="keyword">as</span> $key =&gt; $data) &#123;</span><br><span class="line">            $refer[$data[$pk]] =&amp; $list[$key];</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        foreach ($list <span class="keyword">as</span> $key =&gt; $data) &#123;</span><br><span class="line">            <span class="comment">// 判断是否存在parent</span></span><br><span class="line">            $parentId =  $data[$pid];</span><br><span class="line">            <span class="keyword">if</span> ($root == $parentId) &#123;</span><br><span class="line">                $tree[] =&amp; $list[$key];</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="keyword">if</span> (isset($refer[$parentId])) &#123;</span><br><span class="line">                    $parent =&amp; $refer[$parentId];</span><br><span class="line">                    $parent[$child][] =&amp; $list[$key];</span><br><span class="line">                    <span class="keyword">if</span>($is_count==<span class="literal">true</span>) $parent[<span class="string">'_count'</span>] = count($parent[$child]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $tree;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 将数据格式化成树形结构</span></span><br><span class="line"><span class="comment"> * @param array $items</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">genTree</span>(<span class="params">$items,$pk=<span class="string">'id'</span>,$pid = <span class="string">'pid'</span>, $child = <span class="string">'_child'</span></span>) </span>&#123;</span><br><span class="line">    $tree = []; <span class="comment">//格式化好的树</span></span><br><span class="line">    foreach ($items <span class="keyword">as</span> $item)</span><br><span class="line">        <span class="keyword">if</span> (isset($items[$item[$pid]]))</span><br><span class="line">            $items[$item[$pid]][$child][] = &amp;$items[$item[$pk]];</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            $tree[] = &amp;$items[$item[$pk]];</span><br><span class="line">    <span class="keyword">return</span> $tree;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 多个数组的笛卡尔积</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @param unknown_type $data</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">combineDika</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    $data = func_get_args();</span><br><span class="line">    $data = current($data);</span><br><span class="line">    $cnt = count($data);</span><br><span class="line">    $result = array();</span><br><span class="line">    $arr1 = array_shift($data);</span><br><span class="line">    foreach($arr1 <span class="keyword">as</span> $key=&gt;$item)</span><br><span class="line">    &#123;</span><br><span class="line">        $result[] = array($item);</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    foreach($data <span class="keyword">as</span> $key=&gt;$item)</span><br><span class="line">    &#123;</span><br><span class="line">        $result = combineArray($result,$item);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $result;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 两个数组的笛卡尔积</span></span><br><span class="line"><span class="comment"> * @param  array $arr1 [description]</span></span><br><span class="line"><span class="comment"> * @param  array $arr2 [description]</span></span><br><span class="line"><span class="comment"> * @return [type] [description]</span></span><br><span class="line"><span class="comment"> * @date   2017-08-07</span></span><br><span class="line"><span class="comment"> * @author 赵俊峰 &lt;981248356@qq.com&gt;</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">combineArray</span>(<span class="params">$arr1 =[],$arr2=[]</span>) </span>&#123;</span><br><span class="line">    $result = [];</span><br><span class="line">    foreach ($arr1 <span class="keyword">as</span> $item1)</span><br><span class="line">    &#123;</span><br><span class="line">        foreach ($arr2 <span class="keyword">as</span> $item2)</span><br><span class="line">        &#123;</span><br><span class="line">            $temp = $item1;</span><br><span class="line">            $temp[] = $item2;</span><br><span class="line">            $result[] = $temp;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $result;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 将二维数组以元素的某个值作为键 并归类数组</span></span><br><span class="line"><span class="comment"> * array( array('name'=&gt;'aa','type'=&gt;'pay'), array('name'=&gt;'cc','type'=&gt;'pay') )</span></span><br><span class="line"><span class="comment"> * array('pay'=&gt;array( array('name'=&gt;'aa','type'=&gt;'pay') , array('name'=&gt;'cc','type'=&gt;'pay') ))</span></span><br><span class="line"><span class="comment"> * @param $arr 数组</span></span><br><span class="line"><span class="comment"> * @param $key 分组值的key</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">group_same_key</span>(<span class="params">$arr,$key</span>)</span>&#123;</span><br><span class="line">    $new_arr = array();</span><br><span class="line">    foreach($arr <span class="keyword">as</span> $k=&gt;$v )&#123;</span><br><span class="line">        $new_arr[$v[$key]][] = $v;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $new_arr;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @param $arr</span></span><br><span class="line"><span class="comment"> * @param $key_name</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> * 将数据库中查出的列表以指定的 id 作为数组的键名</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">convert_arr_key</span>(<span class="params">$arr, $key_name=<span class="string">'id'</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $arr2 = [];</span><br><span class="line">    foreach($arr <span class="keyword">as</span> $key =&gt; $val)&#123;</span><br><span class="line">        $arr2[$val[$key_name]] = $val;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $arr2;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 数组 转 对象</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @param array $arr 数组</span></span><br><span class="line"><span class="comment"> * @return object</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_to_object</span>(<span class="params">$arr</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (gettype($arr) != <span class="string">'array'</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $k =&gt; $v) &#123;</span><br><span class="line">        <span class="keyword">if</span> (gettype($v) == <span class="string">'array'</span> || getType($v) == <span class="string">'object'</span>) &#123;</span><br><span class="line">            $arr[$k] = (object)array_to_object($v);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">return</span> (object)$arr;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 对象 转 数组</span></span><br><span class="line"><span class="comment"> * @param object $obj 对象</span></span><br><span class="line"><span class="comment"> * @return array</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">object_to_array</span>(<span class="params">$obj</span>) </span>&#123;</span><br><span class="line">    $obj = (array)$obj;</span><br><span class="line">    foreach ($obj <span class="keyword">as</span> $k =&gt; $v) &#123;</span><br><span class="line">        <span class="keyword">if</span> (gettype($v) == <span class="string">'resource'</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (gettype($v) == <span class="string">'object'</span> || gettype($v) == <span class="string">'array'</span>) &#123;</span><br><span class="line">            $obj[$k] = (array)object_to_array($v);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"> </span><br><span class="line">    <span class="keyword">return</span> $obj;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//将 xml数据转换为数组格式。</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">xml_to_array</span>(<span class="params">$xml</span>)</span>&#123;</span><br><span class="line">    $reg = <span class="string">"/&lt;(\w+)[^&gt;]*&gt;([\\x00-\\xFF]*)&lt;\\/\\1&gt;/"</span>;</span><br><span class="line">    <span class="keyword">if</span>(preg_match_all($reg, $xml, $matches))&#123;</span><br><span class="line">        $count = count($matches[<span class="number">0</span>]);</span><br><span class="line">        <span class="keyword">for</span>($i = <span class="number">0</span>; $i &lt; $count; $i++)&#123;</span><br><span class="line">            $subxml= $matches[<span class="number">2</span>][$i];</span><br><span class="line">            $key = $matches[<span class="number">1</span>][$i];</span><br><span class="line">            <span class="keyword">if</span>(preg_match( $reg, $subxml ))&#123;</span><br><span class="line">                $arr[$key] = xml_to_array( $subxml );</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                $arr[$key] = $subxml;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $arr;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * array_delete  删除数组中的某个值</span></span><br><span class="line"><span class="comment"> * @param $array</span></span><br><span class="line"><span class="comment"> * @param $value</span></span><br><span class="line"><span class="comment"> * @return mixed</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">array_delete</span>(<span class="params">$array, $value</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $key = array_search($value, $array);</span><br><span class="line">    <span class="keyword">if</span> ($key !== <span class="literal">false</span>)</span><br><span class="line">        array_splice($array, $key, <span class="number">1</span>);</span><br><span class="line">    <span class="keyword">return</span> $array;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 分析枚举类型配置值 格式 a:名称1,b:名称2</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">parse_config_attr</span>(<span class="params">$value, $type = null</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">switch</span> ($type) &#123;</span><br><span class="line">        <span class="keyword">default</span>: <span class="comment">//解析"1:1\r\n2:3"格式字符串为数组</span></span><br><span class="line">            $array = preg_split(<span class="string">'/[,;\r\n]+/'</span>, trim($value, <span class="string">",;\r\n"</span>));</span><br><span class="line">            <span class="keyword">if</span> (strpos($value,<span class="string">':'</span>)) &#123;</span><br><span class="line">                $value  = array();</span><br><span class="line">                foreach ($array <span class="keyword">as</span> $val) &#123;</span><br><span class="line">                    list($k, $v) = explode(<span class="string">':'</span>, $val);</span><br><span class="line">                    $value[$k]   = $v;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                $value = $array;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $value;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//array_column()函数兼容低版本PHP</span></span><br><span class="line"><span class="keyword">if</span> (!function_exists(<span class="string">'array_column'</span>)) &#123;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">array_column</span>(<span class="params">$input, $columnKey, $indexKey = null</span>) </span>&#123;</span><br><span class="line">        $columnKeyIsNumber = (is_numeric($columnKey)) ? <span class="literal">true</span> : <span class="literal">false</span>;</span><br><span class="line">        $indexKeyIsNull = (is_null($indexKey)) ? <span class="literal">true</span> : <span class="literal">false</span>;</span><br><span class="line">        $indexKeyIsNumber = (is_numeric($indexKey)) ? <span class="literal">true</span> : <span class="literal">false</span>;</span><br><span class="line">        $result = array();</span><br><span class="line">        foreach ((array) $input <span class="keyword">as</span> $key =&gt; $row) &#123;</span><br><span class="line">            <span class="keyword">if</span> ($columnKeyIsNumber) &#123;</span><br><span class="line">                $tmp = array_slice($row, $columnKey, <span class="number">1</span>);</span><br><span class="line">                $tmp = (is_array($tmp) &amp;&amp; !empty($tmp)) ? current($tmp) : <span class="literal">null</span>;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                $tmp = isset($row[$columnKey]) ? $row[$columnKey] : <span class="literal">null</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (!$indexKeyIsNull) &#123;</span><br><span class="line">                <span class="keyword">if</span> ($indexKeyIsNumber) &#123;</span><br><span class="line">                    $key = array_slice($row, $indexKey, <span class="number">1</span>);</span><br><span class="line">                    $key = (is_array($key) &amp;&amp; !empty($key)) ? current($key) : <span class="literal">null</span>;</span><br><span class="line">                    $key = is_null($key) ? <span class="number">0</span> : $key;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    $key = isset($row[$indexKey]) ? $row[$indexKey] : <span class="number">0</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            $result[$key] = $tmp;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $result;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">http:<span class="comment">//www.jackhhy.cn/article/29/5.html</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-fpm-MongoDB-连接数"><a href="#PHP-fpm-MongoDB-连接数" class="headerlink" title="PHP-fpm MongoDB 连接数"></a>PHP-fpm MongoDB 连接数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">php7 的 MongoDB 扩展中，php 客户端是长连接（及时请求结束，只要 php-fpm 进程没有杀掉，连接就一直保持，目的是下次请求时减少连接带来的性能消耗），并且没有关闭连接的函数。 https:<span class="comment">//learnku.com/laravel/t/34780 </span></span><br><span class="line"></span><br><span class="line">解决办法</span><br><span class="line"></span><br><span class="line">而我们 php-fpm 配置中，pm.min_spare_servers = <span class="number">100</span>，pm.max_spare_servers = <span class="number">200</span>，空闲进程是至少开了 <span class="number">100</span>, 所以大量空闲连接占用了 MongoDB 连接。</span><br><span class="line"></span><br><span class="line">然后我们根据实际情况，配置改为 pm.min_spare_servers = <span class="number">5</span>，pm.max_spare_servers = <span class="number">10</span>。重新部署后解决问题。连接数降了下了，没有超过 <span class="number">100.</span></span><br><span class="line"></span><br><span class="line">总结</span><br><span class="line"></span><br><span class="line">在 PHP7 中，MongoDB 是长连接，一个请求完，对应得 php-fpm 进程没有被 kill 掉化，这个连接不会断开，会一直保持。所以要减少连接个数，需要合理设置 php-fpm 空闲进程数</span><br><span class="line">php7 之后 采用 mongodb 扩展 这个扩展内置的 API 没有关闭连接的方法 所以只能通过 fpm 进程来控制了 实际连接数是由 pm.max_children 控制的 有多少 fpm 进程就会有多少连接 pm.min_spare_servers &amp; pm.min_spare_servers 控制空闲进程数 减少连接占用</span><br><span class="line"></span><br><span class="line">如果是高负载服务器 pm.max_children &amp; pm.min_spare_servers &amp; pm.min_spare_servers 这几项值又不会设置太低 而持久连接对于高并发来说可以减少 IO 开销 但是 mongodb 连接池是由 fpm 进程维护 这样持久连接数会很高 不知道以后会不会专门为 mongodb 开辟进程连接池 优化这块的功能</span><br></pre></td></tr></table></figure>
<h3 id="批量更新"><a href="#批量更新" class="headerlink" title="批量更新"></a>批量更新</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line">$materials = $app-&gt;material-&gt;list($type, <span class="number">0</span>); <span class="comment">// 获取素材列表</span></span><br><span class="line">$page = $materials[<span class="string">'total_count'</span>] / <span class="number">20</span>;</span><br><span class="line"><span class="keyword">for</span> ($x = <span class="number">0</span>; $x &lt;= $page; $x++) &#123;</span><br><span class="line">    $offset = $x * <span class="number">20</span>;</span><br><span class="line">    $materials = $app-&gt;material-&gt;list($type, $offset);</span><br><span class="line">    collect($materials[<span class="string">'item'</span>])-&gt;map(<span class="function"><span class="keyword">function</span> (<span class="params">$v</span>) <span class="title">use</span> (<span class="params">$platformId, $type, $user</span>) </span>&#123;</span><br><span class="line">        WeChatMaterial::query()</span><br><span class="line">            -&gt;updateOrCreate([</span><br><span class="line">                <span class="string">'platform_id'</span> =&gt; $platformId,</span><br><span class="line">                <span class="string">'media_id'</span> =&gt; $v[<span class="string">'media_id'</span>],</span><br><span class="line">            ], [</span><br><span class="line">                <span class="string">'type'</span> =&gt; $type,</span><br><span class="line">                <span class="string">'user_id'</span> =&gt; $user-&gt;id,</span><br><span class="line">                <span class="string">'name'</span> =&gt; $v[<span class="string">'name'</span>],</span><br><span class="line">                <span class="string">'update_time'</span> =&gt; $v[<span class="string">'update_time'</span>],</span><br><span class="line">                <span class="string">'url'</span> =&gt; $v[<span class="string">'url'</span>],</span><br><span class="line">            ]);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$startId = <span class="number">0</span>;</span><br><span class="line">$limit   = <span class="number">20</span>;</span><br><span class="line"><span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">    $materials = $app-&gt;material-&gt;list($type, $startId); <span class="comment">// 获取素材列表</span></span><br><span class="line">    <span class="keyword">if</span> (empty($materials) || empty($materials[<span class="string">'item'</span>])) &#123;</span><br><span class="line">        <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    foreach ($materials[<span class="string">'item'</span>] <span class="keyword">as</span> $k =&gt; $v) &#123;</span><br><span class="line">        WeChatMaterial::query()</span><br><span class="line">            -&gt;updateOrCreate([</span><br><span class="line">                <span class="string">'platform_id'</span> =&gt; $platformId,</span><br><span class="line">                <span class="string">'media_id'</span>    =&gt; $v[<span class="string">'media_id'</span>],</span><br><span class="line">            ], [</span><br><span class="line">                <span class="string">'type'</span>        =&gt; $type,</span><br><span class="line">                <span class="string">'user_id'</span>     =&gt; $user-&gt;id,</span><br><span class="line">                <span class="string">'name'</span>        =&gt; $v[<span class="string">'name'</span>],</span><br><span class="line">                <span class="string">'update_time'</span> =&gt; $v[<span class="string">'update_time'</span>],</span><br><span class="line">                <span class="string">'url'</span>         =&gt; $v[<span class="string">'url'</span>],</span><br><span class="line">            ]);</span><br><span class="line">    &#125;</span><br><span class="line">    $startId = $startId + $limit;</span><br><span class="line">    usleep(<span class="number">200</span>);</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/34751</span></span><br></pre></td></tr></table></figure>
<h3 id="php7-mongodb-分批删除"><a href="#php7-mongodb-分批删除" class="headerlink" title="php7 mongodb 分批删除"></a>php7 mongodb 分批删除</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br></pre></td><td class="code"><pre><span class="line">$limit = <span class="number">1000</span>;</span><br><span class="line">        $skip = <span class="number">0</span>;</span><br><span class="line">        $i = <span class="number">1</span>;</span><br><span class="line">        $log = <span class="keyword">new</span> \App\Models\Log;</span><br><span class="line">        <span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">            $list = $log-&gt;query([], [<span class="string">'skip'</span> =&gt; $skip, <span class="string">'limit'</span> =&gt; $limit, <span class="string">'projection'</span> =&gt; [<span class="string">'_id'</span> =&gt; <span class="number">1</span>],<span class="string">'sort'</span> =&gt; [<span class="string">'_id'</span> =&gt; <span class="number">1</span>]]);</span><br><span class="line">            <span class="keyword">if</span> (!$list) &#123;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            dump(<span class="string">'第'</span>.$i.<span class="string">'次'</span>);</span><br><span class="line">            <span class="keyword">if</span> ($i &gt; <span class="number">2000</span>) &#123;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            $ids = array_column($list, <span class="string">'_id'</span>);</span><br><span class="line">            $messageIds = array_map(<span class="function"><span class="keyword">function</span> (<span class="params">$value</span>)</span>&#123;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">new</span> \MongoDB\BSON\ObjectID($value);</span><br><span class="line">            &#125;, $ids);</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                $c=$log-&gt;<span class="keyword">delete</span>([<span class="string">'_id'</span> =&gt; [<span class="string">'$in'</span> =&gt; $messageIds]]);dump($c);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (\Exception $e) &#123;</span><br><span class="line">                \Log::error(<span class="string">'delete message fail'</span>, [<span class="string">'ids'</span> =&gt; $ids, <span class="string">'msg'</span> =&gt; $e-&gt;getMessage()]);</span><br><span class="line">            &#125;</span><br><span class="line">            $skip += $limit;</span><br><span class="line">            $i++;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">array $attributes=[]</span>) </span>&#123;</span><br><span class="line">        parent::__construct($attributes);</span><br><span class="line">        <span class="keyword">if</span>(version_compare(PHP_VERSION,<span class="string">'7.0'</span>,<span class="string">'&gt;='</span>))&#123;</span><br><span class="line">            $dsn=$<span class="keyword">this</span>-&gt;getDNS();</span><br><span class="line">            $<span class="keyword">this</span>-&gt;manager=<span class="keyword">new</span> \MongoDB\Driver\Manager($dsn);</span><br><span class="line">            $<span class="keyword">this</span>-&gt;writeConcern = <span class="keyword">new</span> \MongoDB\Driver\WriteConcern(<span class="number">1</span>, <span class="number">100</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            \DB::connection(<span class="string">'mongodb'</span>)-&gt;enableQueryLog();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    private <span class="function"><span class="keyword">function</span> <span class="title">getDNS</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        $name=$<span class="keyword">this</span>-&gt;connection;</span><br><span class="line">        $connections=app()-&gt;config[<span class="string">'database.connections'</span>];</span><br><span class="line">        <span class="keyword">if</span> (is_null($config = array_get($connections, $name)))</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> \Exception(<span class="string">"Database [$name] not configured."</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;namespace=$config[<span class="string">'database'</span>].<span class="string">'.'</span>.$<span class="keyword">this</span>-&gt;collection;</span><br><span class="line">        <span class="keyword">if</span> ($config[<span class="string">'username'</span>] &amp;&amp; $config[<span class="string">'password'</span>]) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">'mongodb://'</span>.$config[<span class="string">'username'</span>].<span class="string">":"</span>.rawurlencode($config[<span class="string">'password'</span>]).<span class="string">'@'</span>.$config[<span class="string">'host'</span>].<span class="string">':'</span>.$config[<span class="string">'port'</span>].<span class="string">"/"</span>.$config[<span class="string">'database'</span>].(isset($config[<span class="string">'options'</span>][<span class="string">'replicaSet'</span>])?<span class="string">'?replicaSet='</span>.$config[<span class="string">'options'</span>][<span class="string">'replicaSet'</span>]:<span class="string">''</span>);</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">'mongodb://'</span>.$config[<span class="string">'host'</span>].<span class="string">':'</span>.$config[<span class="string">'port'</span>].<span class="string">"/"</span>.$config[<span class="string">'database'</span>].(isset($config[<span class="string">'options'</span>][<span class="string">'replicaSet'</span>])?<span class="string">'?replicaSet='</span>.$config[<span class="string">'options'</span>][<span class="string">'replicaSet'</span>]:<span class="string">''</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">create</span>(<span class="params">array $attributes</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(count($attributes)&lt;<span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $_id=<span class="keyword">new</span> \MongoDB\BSON\ObjectID();</span><br><span class="line">        $attributes=array_merge($attributes,[<span class="string">'_id'</span>=&gt;$_id]);</span><br><span class="line"></span><br><span class="line">        $bulk=<span class="keyword">new</span> \MongoDB\Driver\BulkWrite([<span class="string">'ordered'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">        $bulk-&gt;insert($attributes);</span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeBulkWrite($<span class="keyword">this</span>-&gt;namespace,  $bulk,  $<span class="keyword">this</span>-&gt;writeConcern);</span><br><span class="line">        &#125;<span class="keyword">catch</span>(\Exception $e)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> (string)$_id;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">insert</span>(<span class="params">array $attributes</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(count($attributes)&lt;<span class="number">1</span>)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $bulk=<span class="keyword">new</span> \MongoDB\Driver\BulkWrite([<span class="string">'ordered'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">        foreach($attributes <span class="keyword">as</span> $at)&#123;</span><br><span class="line">            $bulk-&gt;insert($at);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span>&#123;</span><br><span class="line">            $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeBulkWrite($<span class="keyword">this</span>-&gt;namespace,  $bulk,  $<span class="keyword">this</span>-&gt;writeConcern);</span><br><span class="line">        &#125;<span class="keyword">catch</span>(\Exception $e)&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $result-&gt;getInsertedCount();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">update</span>(<span class="params">$where = [], $update = [], $upsert = false</span>) </span>&#123;</span><br><span class="line">        $bulk = <span class="keyword">new</span> \MongoDB\Driver\BulkWrite([<span class="string">'ordered'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">        $bulk-&gt;update($where, [<span class="string">'$set'</span> =&gt; $update], [<span class="string">'multi'</span> =&gt; <span class="literal">true</span>, <span class="string">'upsert'</span> =&gt; $upsert]);</span><br><span class="line">        $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeBulkWrite($<span class="keyword">this</span>-&gt;namespace, $bulk, $<span class="keyword">this</span>-&gt;writeConcern);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $result-&gt;getModifiedCount();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">delete</span>(<span class="params">$where = [], $limit = <span class="number">0</span></span>) </span>&#123;</span><br><span class="line">        $bulk = <span class="keyword">new</span> \MongoDB\Driver\BulkWrite([<span class="string">'ordered'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">        $bulk-&gt;<span class="keyword">delete</span>($where, [<span class="string">'limit'</span> =&gt; $limit]);<span class="comment">//limit 为 0 时，删除所有匹配数据</span></span><br><span class="line">        $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeBulkWrite($<span class="keyword">this</span>-&gt;namespace, $bulk, $<span class="keyword">this</span>-&gt;writeConcern);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $result-&gt;getDeletedCount();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">count</span>(<span class="params">$where = []</span>) </span>&#123;</span><br><span class="line">        $command = <span class="keyword">new</span> \MongoDB\Driver\Command([<span class="string">'count'</span> =&gt; $<span class="keyword">this</span>-&gt;collection, <span class="string">'query'</span> =&gt; $where]);</span><br><span class="line">        $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeCommand(explode(<span class="string">'.'</span>, $<span class="keyword">this</span>-&gt;namespace)[<span class="number">0</span>], $command);</span><br><span class="line">        $res = $result-&gt;toArray();</span><br><span class="line">        $count = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">            $count = $res[<span class="number">0</span>]-&gt;n;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $count;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">query</span>(<span class="params">$where = [], $option = []</span>) </span>&#123;</span><br><span class="line">        $query = <span class="keyword">new</span> \MongoDB\Driver\Query($where, $option);<span class="comment">//http://php.net/manual/zh/mongodb-driver-manager.executequery.php</span></span><br><span class="line">        $result = $<span class="keyword">this</span>-&gt;manager-&gt;executeQuery($<span class="keyword">this</span>-&gt;namespace, $query);</span><br><span class="line">        $res = [];</span><br><span class="line">        foreach ($result <span class="keyword">as</span> $value)&#123;</span><br><span class="line">            $v = (array)$value;</span><br><span class="line">            $v[<span class="string">'_id'</span>] = (string)$v[<span class="string">'_id'</span>];</span><br><span class="line">            $res[] = $v;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $res;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="头部插入内容"><a href="#头部插入内容" class="headerlink" title="头部插入内容"></a>头部插入内容</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">如果是图片开头，在图片后面插入文字，如果不是图片开头，直接插入文字到头部</span><br><span class="line">preg_match(<span class="string">'#^(&lt;img class="img" src=.*"/&gt;)*(.*)#'</span>,$data, $m);</span><br><span class="line">            <span class="keyword">if</span> ($m &amp;&amp; isset($m[<span class="number">1</span>]) &amp;&amp; isset($m[<span class="number">2</span>])) &#123;</span><br><span class="line">                $data = $m[<span class="number">1</span>].$ad.$m[<span class="number">2</span>];</span><br><span class="line">            &#125;</span><br></pre></td></tr></table></figure>
<h3 id="生成按时间增长的全局唯一主键"><a href="#生成按时间增长的全局唯一主键" class="headerlink" title="生成按时间增长的全局唯一主键"></a>生成按时间增长的全局唯一主键</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getGenerateId</span> (<span class="params">$len = <span class="number">12</span></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">      $temp = random_bytes($len);</span><br><span class="line"></span><br><span class="line">      <span class="keyword">return</span> bin2hex($temp);</span><br><span class="line">&#125;</span><br><span class="line">使用 mongo 扩展 <span class="keyword">new</span> \MongoDB\BSON\ObjectID ()</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">generate_id_hex</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> $i = <span class="number">0</span>;</span><br><span class="line">    $i OR $i = mt_rand(<span class="number">1</span>, <span class="number">0x7FFFFF</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> sprintf(<span class="string">"%08x%06x%04x%06x"</span>,</span><br><span class="line">        <span class="comment">/* 4-byte value representing the seconds since the Unix epoch. */</span></span><br><span class="line">        time() &amp; <span class="number">0xFFFFFFFF</span>,</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* 3-byte machine identifier.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * On windows, the max length is 256. Linux doesn't have a limit, but it</span></span><br><span class="line"><span class="comment">         * will fill in the first 256 chars of hostname even if the actual</span></span><br><span class="line"><span class="comment">         * hostname is longer. </span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * From the GNU manual:</span></span><br><span class="line"><span class="comment">         * gethostname stores the beginning of the host name in name even if the</span></span><br><span class="line"><span class="comment">         * host name won't entirely fit. For some purposes, a truncated host name</span></span><br><span class="line"><span class="comment">         * is good enough. If it is, you can ignore the error code.</span></span><br><span class="line"><span class="comment">         *</span></span><br><span class="line"><span class="comment">         * crc32 will be better than Times33. */</span></span><br><span class="line">        crc32(substr((string)gethostname(), <span class="number">0</span>, <span class="number">256</span>)) &gt;&gt; <span class="number">8</span> &amp; <span class="number">0xFFFFFF</span>,</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* 2-byte process id. */</span></span><br><span class="line">        getmypid() &amp; <span class="number">0xFFFF</span>,</span><br><span class="line"></span><br><span class="line">        <span class="comment">/* 3-byte counter, starting with a random value. */</span></span><br><span class="line">        $i = $i &gt; <span class="number">0xFFFFFE</span> ? <span class="number">1</span> : $i + <span class="number">1</span></span><br><span class="line">    );</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> ($j=<span class="number">0</span>; $j &lt;<span class="number">100</span> ; $j++) &#123; </span><br><span class="line">    echo generate_id_hex();</span><br><span class="line">    echo <span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">    # code...</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/34849</span></span><br></pre></td></tr></table></figure>
<h3 id="array-search-和-in-array-函数效率问题"><a href="#array-search-和-in-array-函数效率问题" class="headerlink" title="array_search 和 in_array 函数效率问题"></a>array_search 和 in_array 函数效率问题</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">采用 array_flip 翻转后，用 isset 代替 in_array 函数，用 $array[key] 替代 array_search, 这样能解决大数组超时耗时问题</span><br><span class="line">$needle = <span class="string">'test for this'</span>;</span><br><span class="line"></span><br><span class="line">$flipped_haystack = array_flip($haystack);</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ( isset($flipped_haystack[$needle]) )</span><br><span class="line">&#123;</span><br><span class="line">  print <span class="string">"Yes it's there!"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="把array或json以array字符串的形式输出"><a href="#把array或json以array字符串的形式输出" class="headerlink" title="把array或json以array字符串的形式输出"></a>把array或json以array字符串的形式输出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Utils</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 把array或json以array字符串的形式输出 等同于var_export</span></span><br><span class="line"><span class="comment">     * @param $str</span></span><br><span class="line"><span class="comment">     * @return string</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">outPutArray</span>(<span class="params">$str</span>): <span class="title">string</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (is_string($str)) &#123;</span><br><span class="line">            $arr = json_decode($str, <span class="literal">true</span>);</span><br><span class="line">            <span class="keyword">if</span> (is_null($arr)) &#123;</span><br><span class="line">                $ret_str = <span class="string">''</span>;</span><br><span class="line">                <span class="keyword">if</span> (is_numeric($str)) &#123;</span><br><span class="line">                    $ret_str .= <span class="string">'['</span> .PHP_EOL. $str .PHP_EOL. <span class="string">']'</span>;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    $ret_str .= <span class="string">'['</span> .PHP_EOL. <span class="string">'\''</span>.$str .<span class="string">'\''</span>.PHP_EOL. <span class="string">']'</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> $ret_str;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            $arr = $str;</span><br><span class="line">        &#125;</span><br><span class="line">        $str = <span class="string">'['</span> . PHP_EOL;</span><br><span class="line">        foreach ($arr <span class="keyword">as</span> $key =&gt; $value) &#123;</span><br><span class="line">            <span class="keyword">if</span> (!is_numeric($key)) &#123;</span><br><span class="line">                $str .= <span class="string">"'&#123;$key&#125;' =&gt; "</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (is_array($value)) &#123;</span><br><span class="line">                $str .= self::outPutArray($value);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="keyword">if</span> (is_string($value)) &#123;</span><br><span class="line">                    $str .= <span class="string">"'&#123;$value&#125;',"</span> . PHP_EOL;</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    $str .= <span class="string">"&#123;$value&#125;,"</span> . PHP_EOL;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        $str .= <span class="string">'],'</span> . PHP_EOL;</span><br><span class="line">        <span class="keyword">return</span> $str;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">echo Utils::outPutArray(<span class="string">'shiwenyuan'</span>);</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> * 'shiwenyuan'</span></span><br><span class="line"><span class="comment"> * ]</span></span><br><span class="line"><span class="comment"> * */</span></span><br><span class="line">echo Utils::outPutArray([<span class="string">'name'</span>=&gt;<span class="string">'zhangsan'</span>, <span class="string">'age'</span>=&gt;<span class="number">18</span>, <span class="string">'friend'</span>=&gt;[[<span class="string">'name'</span>=&gt;<span class="string">'lisi'</span>, <span class="string">'age'</span>=&gt;<span class="number">19</span>], [<span class="string">'name'</span>=&gt;<span class="string">'wangwu'</span>, <span class="string">'age'</span>=&gt;<span class="number">20</span>]]]);</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> *'name' =&gt; 'zhangsan',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 18,</span></span><br><span class="line"><span class="comment"> * 'friend' =&gt; [</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> * 'name' =&gt; 'lisi',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 19,</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> * 'name' =&gt; 'wangwu',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 20,</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * ]</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">echo Utils::outPutArray(<span class="string">'&#123;"name":"zhangsan","age":18,"friend":[&#123;"name":"lisi","age":19&#125;,&#123;"name":"wangwu","age":21&#125;]&#125;'</span>);</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> *'name' =&gt; 'zhangsan',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 18,</span></span><br><span class="line"><span class="comment"> * 'friend' =&gt; [</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> * 'name' =&gt; 'lisi',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 19,</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * [</span></span><br><span class="line"><span class="comment"> * 'name' =&gt; 'wangwu',</span></span><br><span class="line"><span class="comment"> * 'age' =&gt; 20,</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * ],</span></span><br><span class="line"><span class="comment"> * ]</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line">https:<span class="comment">//shiwenyuan.github.io/post/ck1irc5wh000fq2fyv61xflc6.html</span></span><br></pre></td></tr></table></figure>
<h3 id="unicode-转中文"><a href="#unicode-转中文" class="headerlink" title="unicode 转中文"></a>unicode 转中文</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">UnicodeEncode</span>(<span class="params">$str</span>)</span>&#123;</span><br><span class="line">    <span class="comment">//split word</span></span><br><span class="line">    preg_match_all(<span class="string">'/./u'</span>,$str,$matches);</span><br><span class="line"> </span><br><span class="line">    $unicodeStr = <span class="string">""</span>;</span><br><span class="line">    foreach($matches[<span class="number">0</span>] <span class="keyword">as</span> $m)&#123;</span><br><span class="line">        <span class="comment">//拼接</span></span><br><span class="line">        $unicodeStr .= <span class="string">"&amp;#"</span>.base_convert(bin2hex(iconv(<span class="string">'UTF-8'</span>,<span class="string">"UCS-4"</span>,$m)),<span class="number">16</span>,<span class="number">10</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $unicodeStr;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">$str = <span class="string">"新浪微博"</span>;</span><br><span class="line">echo UnicodeEncode($str)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">unicodeDecode</span>(<span class="params">$unicode_str</span>)</span>&#123;</span><br><span class="line">    $json = <span class="string">'&#123;"str":"'</span>.$unicode_str.<span class="string">'"&#125;'</span>;</span><br><span class="line">    $arr = json_decode($json,<span class="literal">true</span>);</span><br><span class="line">    <span class="keyword">if</span>(empty($arr)) <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">    <span class="keyword">return</span> $arr[<span class="string">'str'</span>];</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">$unicode_str = <span class="string">"\u65b0\u6d6a\u5fae\u535a"</span>;</span><br><span class="line">echo unicodeDecode($unicode_str);</span><br><span class="line"></span><br><span class="line">js:</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">convert2Unicode</span>(<span class="params">str</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> str.replace(<span class="regexp">/[\u0080-\uffff]/g</span>,</span><br><span class="line">    <span class="function"><span class="keyword">function</span>(<span class="params">$<span class="number">0</span></span>) </span>&#123;</span><br><span class="line">        <span class="keyword">var</span> tmp = $<span class="number">0.</span>charCodeAt(<span class="number">0</span>).toString(<span class="number">16</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"\u"</span> + <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">5</span> - tmp.length).join(<span class="string">'0'</span>) + tmp;</span><br><span class="line">    &#125;);</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">unicode2utf8</span>(<span class="params">$str</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(!$str) <span class="keyword">return</span> $str;</span><br><span class="line">        $decode = json_decode($str);</span><br><span class="line">        <span class="keyword">if</span>($decode) <span class="keyword">return</span> $decode;</span><br><span class="line">        $str = <span class="string">'["'</span> . $str . <span class="string">'"]'</span>;</span><br><span class="line">        $decode = json_decode($str);</span><br><span class="line">        <span class="keyword">if</span>(count($decode) == <span class="number">1</span>)&#123;</span><br><span class="line">                <span class="keyword">return</span> $decode[<span class="number">0</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $str;</span><br><span class="line">        </span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">decodeUnicode</span>(<span class="params">$str</span>)</span>&#123;</span><br><span class="line">         <span class="keyword">return</span> preg_replace_callback(<span class="string">'/\\\\u([0-9a-f]&#123;4&#125;)/i'</span>, create_function(<span class="string">'$matches'</span>, <span class="string">'return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));'</span>), $str);</span><br><span class="line">$unicodeChar = <span class="string">"\u56de\u590d\uff1a"</span>;</span><br><span class="line">echo  json_decode(<span class="string">'"'</span>.$unicodeChar.<span class="string">'"'</span>);       </span><br><span class="line">  https:<span class="comment">//segmentfault.com/a/1190000003020776</span></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * utf8字符转换成Unicode字符</span></span><br><span class="line"><span class="comment">   * @param  [type] $utf8_str Utf-8字符</span></span><br><span class="line"><span class="comment">   * @return [type]           Unicode字符</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">utf8_str_to_unicode</span>(<span class="params">$utf8_str</span>) </span>&#123;</span><br><span class="line">      $unicode = <span class="number">0</span>;</span><br><span class="line">      $unicode = (ord($utf8_str[<span class="number">0</span>]) &amp; <span class="number">0x1F</span>) &lt;&lt; <span class="number">12</span>;</span><br><span class="line">      $unicode |= (ord($utf8_str[<span class="number">1</span>]) &amp; <span class="number">0x3F</span>) &lt;&lt; <span class="number">6</span>;</span><br><span class="line">      $unicode |= (ord($utf8_str[<span class="number">2</span>]) &amp; <span class="number">0x3F</span>);</span><br><span class="line">      <span class="keyword">return</span> dechex($unicode);</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * Unicode字符转换成utf8字符</span></span><br><span class="line"><span class="comment">   * @param  [type] $unicode_str Unicode字符</span></span><br><span class="line"><span class="comment">   * @return [type]              Utf-8字符</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">unicode_to_utf8</span>(<span class="params">$unicode_str</span>) </span>&#123;</span><br><span class="line">      $utf8_str = <span class="string">''</span>;</span><br><span class="line">      $code = intval(hexdec($unicode_str));</span><br><span class="line">      <span class="comment">//这里注意转换出来的code一定得是整形，这样才会正确的按位操作</span></span><br><span class="line">      $ord_1 = decbin(<span class="number">0xe0</span> | ($code &gt;&gt; <span class="number">12</span>));</span><br><span class="line">      $ord_2 = decbin(<span class="number">0x80</span> | (($code &gt;&gt; <span class="number">6</span>) &amp; <span class="number">0x3f</span>));</span><br><span class="line">      $ord_3 = decbin(<span class="number">0x80</span> | ($code &amp; <span class="number">0x3f</span>));</span><br><span class="line">      $utf8_str = chr(bindec($ord_1)) . chr(bindec($ord_2)) . chr(bindec($ord_3));</span><br><span class="line">      <span class="keyword">return</span> $utf8_str;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h3 id="开放API接口签名验证"><a href="#开放API接口签名验证" class="headerlink" title="开放API接口签名验证"></a>开放API接口签名验证</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">AccessKey&amp;SecretKey （开放平台）</span><br><span class="line"></span><br><span class="line">请求身份</span><br><span class="line"></span><br><span class="line">为开发者分配AccessKey（开发者标识，确保唯一）和SecretKey（用于接口加密，确保不易被穷举，生成算法不易被猜测）。</span><br><span class="line"></span><br><span class="line">防止篡改</span><br><span class="line"></span><br><span class="line">参数签名</span><br><span class="line"></span><br><span class="line">按照请求参数名的字母升序排列非空请求参数（包含AccessKey），使用URL键值对的格式（即key1=value1&amp;key2=value2…）拼接成字符串stringA；</span><br><span class="line">在stringA最后拼接上Secretkey得到字符串stringSignTemp；</span><br><span class="line">对stringSignTemp进行MD5运算，并将得到的字符串所有字符转换为大写，得到sign值。</span><br><span class="line">请求携带参数AccessKey和Sign，只有拥有合法的身份AccessKey和正确的签名Sign才能放行。这样就解决了身份验证和参数篡改问题，即使请求参数被劫持，由于获取不到SecretKey（仅作本地加密使用，不参与网络传输），无法伪造合法的请求。</span><br><span class="line"></span><br><span class="line">重放攻击</span><br><span class="line"></span><br><span class="line">虽然解决了请求参数被篡改的隐患，但是还存在着重复使用请求参数伪造二次请求的隐患。</span><br><span class="line"></span><br><span class="line">timestamp+nonce方案</span><br><span class="line"></span><br><span class="line">nonce指唯一的随机字符串，用来标识每个被签名的请求。通过为每个请求提供一个唯一的标识符，服务器能够防止请求被多次使用（记录所有用过的nonce以阻止它们被二次使用）。</span><br><span class="line"></span><br><span class="line">然而，对服务器来说永久存储所有接收到的nonce的代价是非常大的。可以使用timestamp来优化nonce的存储。</span><br><span class="line"></span><br><span class="line">假设允许客户端和服务端最多能存在<span class="number">15</span>分钟的时间差，同时追踪记录在服务端的nonce集合。当有新的请求进入时，首先检查携带的timestamp是否在<span class="number">15</span>分钟内，如超出时间范围，则拒绝，然后查询携带的nonce，如存在已有集合，则拒绝。否则，记录该nonce，并删除集合内时间戳大于<span class="number">15</span>分钟的nonce（可以使用redis的expire，新增nonce的同时设置它的超时失效时间为<span class="number">15</span>分钟）。</span><br><span class="line"></span><br><span class="line">实现</span><br><span class="line"></span><br><span class="line">请求接口：http:<span class="comment">//api.test.com/test?name=hello&amp;home=world&amp;work=java</span></span><br><span class="line"></span><br><span class="line">客户端</span><br><span class="line"></span><br><span class="line">生成当前时间戳timestamp=now和唯一随机字符串nonce=random</span><br><span class="line">按照请求参数名的字母升序排列非空请求参数（包含AccessKey) </span><br><span class="line">stringA=<span class="string">"AccessKey=access&amp;home=world&amp;name=hello&amp;work=java&amp;timestamp=now&amp;nonce=random"</span>;</span><br><span class="line">拼接密钥SecretKey </span><br><span class="line">stringSignTemp=<span class="string">"AccessKey=access&amp;home=world&amp;name=hello&amp;work=java&amp;timestamp=now&amp;nonce=random&amp;SecretKey=secret"</span>;</span><br><span class="line">MD5并转换为大写 </span><br><span class="line">sign=MD5(stringSignTemp).toUpperCase();</span><br><span class="line">最终请求 </span><br><span class="line">http:<span class="comment">//api.test.com/test?name=hello&amp;home=world&amp;work=java&amp;timestamp=now&amp;nonce=nonce&amp;sign=sign;</span></span><br><span class="line"> https:<span class="comment">//blog.csdn.net/qq_18495465/article/details/79248608</span></span><br></pre></td></tr></table></figure>
<h3 id="PhpSpreadsheet-小教程"><a href="#PhpSpreadsheet-小教程" class="headerlink" title="PhpSpreadsheet 小教程"></a>PhpSpreadsheet 小教程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">&gt; composer <span class="built_in">require</span> phpoffice/phpspreadsheet</span><br><span class="line">&lt;?php</span><br><span class="line"><span class="built_in">require</span> <span class="string">'vendor/autoload.php'</span>;</span><br><span class="line"></span><br><span class="line">use PhpOffice\PhpSpreadsheet\Spreadsheet;</span><br><span class="line">use PhpOffice\PhpSpreadsheet\Writer\Xlsx;</span><br><span class="line"></span><br><span class="line">$spreadsheet = <span class="keyword">new</span> Spreadsheet();</span><br><span class="line">$sheet = $spreadsheet-&gt;getActiveSheet();</span><br><span class="line">$sheet-&gt;setCellValue(<span class="string">'A1'</span>, <span class="string">'Hello World !'</span>);</span><br><span class="line"></span><br><span class="line">$writer = <span class="keyword">new</span> Xlsx($spreadsheet);</span><br><span class="line">$writer-&gt;save(<span class="string">'hello world.xlsx'</span>);</span><br><span class="line">实例</span><br><span class="line"></span><br><span class="line">包中带了实例代码，位置 vendor/phpoffice/phpspreadsheet/samples 下</span><br><span class="line"></span><br><span class="line">&gt; php -S localhost:<span class="number">8000</span> -t vendor/phpoffice/phpspreadsheet/samples</span><br><span class="line"></span><br><span class="line">$inputFileType = <span class="string">'Xls'</span>;</span><br><span class="line">$inputFileName = <span class="string">'./sampleData/example1.xls'</span>;</span><br><span class="line"></span><br><span class="line">$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);</span><br><span class="line"><span class="comment">/**  只要数据  **/</span></span><br><span class="line">$reader-&gt;setReadDataOnly(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">$spreadsheet = $reader-&gt;load($inputFileName);</span><br><span class="line"></span><br><span class="line">$spreadsheet = PhpOffice\PhpSpreadsheet\IOFactory::load(<span class="string">"new.xls"</span>);</span><br><span class="line"></span><br><span class="line">$data = $spreadsheet</span><br><span class="line">            -&gt;getSheet(<span class="number">0</span>) <span class="comment">// 指定第一个工作表为当前</span></span><br><span class="line">            -&gt;toArray();  <span class="comment">// 转为数组</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 或者得到全部工作表的数据数组           </span></span><br><span class="line">$cells=array();</span><br><span class="line"><span class="comment">// 工作表对象有迭代器实现</span></span><br><span class="line">foreach ( $spreadsheet-&gt;getWorksheetIterator() <span class="keyword">as</span> $data ) &#123;</span><br><span class="line">    $cells = $data-&gt;toArray();</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/30048</span></span><br></pre></td></tr></table></figure>
<h3 id="进制转换"><a href="#进制转换" class="headerlink" title="进制转换"></a>进制转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$res=bin2hex(openssl_encrypt(<span class="string">'test'</span>,<span class="string">'AES-128-ECB'</span>,$key,OPENSSL_RAW_DATA));</span><br><span class="line">通过以上函数把 test 转换成 <span class="number">16</span> 进制</span><br><span class="line"></span><br><span class="line">openssl_decrypt(pack(<span class="string">'H*'</span>,$res),<span class="string">'AES-128-ECB'</span>,$key,OPENSSL_RAW_DATA);</span><br><span class="line">再用以上函数把 <span class="number">16</span> 进制转换回来成 test</span><br></pre></td></tr></table></figure>
<h3 id="https证书"><a href="#https证书" class="headerlink" title="https证书"></a>https证书</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">wget https:<span class="comment">//dl.eff.org/certbot-auto</span></span><br><span class="line">chmod a+x certbot-auto</span><br><span class="line">假设你的域名 mengdodo.com，想获取根域名 https 证书</span><br><span class="line">./certbot-auto certonly -d mengdodo.com -d *.mengdodo.com --manual --preferred-challenges dns<span class="number">-01</span> --server https:<span class="comment">//acme-v02.api.letsencrypt.org/directory</span></span><br><span class="line">然后按照提示完成两个 txt 解析即可 https，使用 acme.sh 可以申请免费了，我好几项目用了。</span><br></pre></td></tr></table></figure>
<h3 id="composer"><a href="#composer" class="headerlink" title="composer"></a>composer</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Composer 国内镜像及多线程下载利器 hirak/prestissimo composer config -g repo.packagist composer https:<span class="comment">//mirrors.aliyun.com/composer/</span></span><br><span class="line"></span><br><span class="line">composer global <span class="built_in">require</span> hirak/prestissimo</span><br><span class="line">composer  clearcache</span><br></pre></td></tr></table></figure>
<h3 id="Composer-提示-zlib-decode-data-error"><a href="#Composer-提示-zlib-decode-data-error" class="headerlink" title="Composer 提示 zlib_decode (): data error"></a>Composer 提示 zlib_decode (): data error</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$ composer config repo.packagist composer http:<span class="comment">//packagist.phpcomposer.com</span></span><br><span class="line">composer config -g --unset repos.packagist</span><br><span class="line">composer config --unset repos.packagist</span><br><span class="line">composer clearcache</span><br><span class="line">composer diagnose</span><br><span class="line">composer install -vvv</span><br><span class="line">https:<span class="comment">//learnku.com/articles/35106</span></span><br></pre></td></tr></table></figure>
<h3 id="swoole-进程退出"><a href="#swoole-进程退出" class="headerlink" title="swoole 进程退出"></a>swoole 进程退出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">swoole_process::signal(SIGALRM,<span class="function"><span class="keyword">function</span> (<span class="params"></span>)</span>&#123;</span><br><span class="line">    echo <span class="string">"1\n"</span>;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">swoole_process::alarm(<span class="number">100</span>*<span class="number">1000</span>);</span><br><span class="line"></span><br><span class="line">swoole_timer_tick(<span class="number">2000</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$timer_id</span>) </span>&#123;</span><br><span class="line">    echo <span class="string">"执行 $timer_id"</span> . PHP_EOL;</span><br><span class="line">&#125;);</span><br><span class="line">root@687d4c789947:/var/www/swoole2# php timer.php</span><br><span class="line">执行 <span class="number">1</span></span><br><span class="line">执行 <span class="number">1</span></span><br><span class="line">执行 <span class="number">1</span></span><br><span class="line"></span><br><span class="line">use Swoole\Process;<span class="comment">//引入类的命名空间【对应根目录】</span></span><br><span class="line"><span class="comment">//安装信号处理器 SIGALRM定时信号  【可以由定时器产生，或是进程发出如pcntl_kill【c是kill】】或是在终端输入kill -s 信号编号或-n 信号值 进程标识符号【进程标识符号可以在代码中通过posix_getpid或是在/proc/PID/目录下查看进程详细数据】   </span></span><br><span class="line">Process::signal(SIGALRM, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> $i = <span class="number">0</span>;</span><br><span class="line">    echo <span class="string">"#&#123;$i&#125;\talarm\n"</span>;</span><br><span class="line">    $i++;</span><br><span class="line">    <span class="keyword">if</span> ($i &gt; <span class="number">20</span>) &#123;</span><br><span class="line">        Process::alarm(<span class="number">-1</span>);<span class="comment">//定时器清0操作</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//100ms</span></span><br><span class="line">Process::alarm(<span class="number">100</span> * <span class="number">1000</span>);   <span class="comment">//定时器，swoole已经做了封装，默认会阻塞进程【当时间到的时候，系统会唤醒该进程，并发出中断请求,中断处理函数将会收到定时中断，并运行中断处理函数，运行到20后，自动清0，同时进程阻塞。       </span></span><br><span class="line"></span><br><span class="line">阻塞：是指操作系统把当前进程释放cpu使用权，此时cpu干其它事情了，产生阻塞的场景如等待网络IO,读写请求等操作       </span><br><span class="line">非阻塞：执行请求后，立马返回   </span><br><span class="line"></span><br><span class="line">swoole 版本多少，<span class="number">4.4</span>+ signal 监听不会加入事件循环了，也就是程序会自动退出。。。</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/35076</span></span><br></pre></td></tr></table></figure>
<h3 id="常用正则表达式"><a href="#常用正则表达式" class="headerlink" title="常用正则表达式"></a>常用正则表达式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">数字：^[<span class="number">0</span><span class="number">-9</span>]*$</span><br><span class="line">n位的数字：^\d&#123;n&#125;$</span><br><span class="line">至少n位的数字：^\d&#123;n,&#125;$</span><br><span class="line">m-n位的数字：^\d&#123;m,n&#125;$</span><br><span class="line">零和非零开头的数字：^(<span class="number">0</span>|[<span class="number">1</span><span class="number">-9</span>][<span class="number">0</span><span class="number">-9</span>]*)$</span><br><span class="line">非零开头的最多带两位小数的数字：^([<span class="number">1</span><span class="number">-9</span>][<span class="number">0</span><span class="number">-9</span>]*)+(.[<span class="number">0</span><span class="number">-9</span>]&#123;<span class="number">1</span>,<span class="number">2</span>&#125;)?$</span><br><span class="line">带<span class="number">1</span><span class="number">-2</span>位小数的正数或负数：^(\-)?\d+(\.\d&#123;<span class="number">1</span>,<span class="number">2</span>&#125;)?$</span><br><span class="line">正数、负数、和小数：^(\-|\+)?\d+(\.\d+)?$</span><br><span class="line">有两位小数的正实数：^[<span class="number">0</span><span class="number">-9</span>]+(.[<span class="number">0</span><span class="number">-9</span>]&#123;<span class="number">2</span>&#125;)?$</span><br><span class="line">有<span class="number">1</span>~<span class="number">3</span>位小数的正实数：^[<span class="number">0</span><span class="number">-9</span>]+(.[<span class="number">0</span><span class="number">-9</span>]&#123;<span class="number">1</span>,<span class="number">3</span>&#125;)?$</span><br><span class="line">非零的正整数：^[<span class="number">1</span><span class="number">-9</span>]\d*$ 或 ^([<span class="number">1</span><span class="number">-9</span>][<span class="number">0</span><span class="number">-9</span>]*)&#123;<span class="number">1</span>,<span class="number">3</span>&#125;$ 或 ^\+?[<span class="number">1</span><span class="number">-9</span>][<span class="number">0</span><span class="number">-9</span>]*$</span><br><span class="line">非零的负整数：^\-[<span class="number">1</span><span class="number">-9</span>][]<span class="number">0</span><span class="number">-9</span><span class="string">"*$ 或 ^-[1-9]\d*$</span></span><br><span class="line"><span class="string">非负整数：^\d+$ 或 ^[1-9]\d*|0$</span></span><br><span class="line"><span class="string">非正整数：^-[1-9]\d*|0$ 或 ^((-\d+)|(0+))$</span></span><br><span class="line"><span class="string">非负浮点数：^\d+(\.\d+)?$ 或 ^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$</span></span><br><span class="line"><span class="string">非正浮点数：^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$</span></span><br><span class="line"><span class="string">正浮点数：^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ 或 ^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$</span></span><br><span class="line"><span class="string">负浮点数：^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ 或 ^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$</span></span><br><span class="line"><span class="string">浮点数：^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$</span></span><br><span class="line"><span class="string">http://yyeer.com/%E7%BC%96%E7%A8%8B/2019/06/30/%E6%94%B6%E9%9B%86-%E5%B8%B8%E7%94%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/</span></span><br></pre></td></tr></table></figure>
<h3 id="图片加水印"><a href="#图片加水印" class="headerlink" title="图片加水印"></a>图片加水印</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* </span></span><br><span class="line"><span class="comment"> * 图片加水印函数</span></span><br><span class="line"><span class="comment"> * $dst_file : 处理完成后保存到此文件路径</span></span><br><span class="line"><span class="comment"> * $src_file ：待处理的图片文件路径</span></span><br><span class="line"><span class="comment"> * $logo_file：水印的图片文件路径</span></span><br><span class="line"><span class="comment"> * $top      ：上间距</span></span><br><span class="line"><span class="comment"> * $left     ：左间距</span></span><br><span class="line"><span class="comment"> * $alpha    ：透明度(0-100)【特别注意：若logo_file本身已有透明效果，请务必传false】</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">fullFillLogos</span>(<span class="params">$dst_file, $src_file, $logo_file, $top=<span class="number">0</span>, $left=<span class="number">0</span>, $alpha=false</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">//创建图片的实例</span></span><br><span class="line">        $dst = imagecreatefromstring(file_get_contents($src_file));</span><br><span class="line">        $logo = imagecreatefromstring(file_get_contents($logo_file));</span><br><span class="line">        <span class="comment">//获取宽高</span></span><br><span class="line">        list($logo_w, $logo_h) = getimagesize($logo_file);</span><br><span class="line">        list($dst_w, $dst_h) = getimagesize($src_file);</span><br><span class="line">        <span class="comment">//循环铺上水印</span></span><br><span class="line">        <span class="keyword">for</span>($off_y=$top; $off_y+$top&lt;$dst_h; $off_y+=$logo_h+$top) &#123;</span><br><span class="line">            <span class="keyword">for</span>($off_x=$left; $off_x+$left&lt;$dst_w; $off_x+=$logo_w+$left) &#123;</span><br><span class="line">                $width = ($off_x+$logo_w+$left&gt;$dst_w) ? ($dst_w-$off_x-$left) : $logo_w;</span><br><span class="line">                $height = ($off_y+$logo_h+$top&gt;$dst_h) ? ($dst_h-$off_y-$top) : $logo_h;</span><br><span class="line">                <span class="keyword">if</span>($alpha === <span class="literal">false</span>) &#123;</span><br><span class="line">                    imagecopy($dst, $logo, $off_x, $off_y, <span class="number">0</span>, <span class="number">0</span>, $width, $height);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    imagecopymerge($dst, $logo, $off_x, $off_y, <span class="number">0</span>, <span class="number">0</span>, $width, $height, $alpha);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//水印完成, 存档...</span></span><br><span class="line">        header(<span class="string">'Content-Type: image/jpeg'</span>);</span><br><span class="line">        imagejpeg($dst, $dst_file);</span><br><span class="line">        imagedestroy($dst);</span><br><span class="line">        imagedestroy($logo);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;http:<span class="comment">//yyeer.com/%E7%BC%96%E7%A8%8B/2017/12/08/%E4%BD%BF%E7%94%A8GD%E5%BA%93%E7%BB%99%E5%9B%BE%E7%89%87%E9%93%BA%E6%BB%A1%E6%B0%B4%E5%8D%B0/</span></span><br></pre></td></tr></table></figure>
<h3 id="素数while循环的分析"><a href="#素数while循环的分析" class="headerlink" title="素数while循环的分析"></a>素数while循环的分析</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">isprime</span>(<span class="params">$num</span>) </span>&#123;</span><br><span class="line">    $count = (int) sqrt($num);</span><br><span class="line">    <span class="keyword">while</span> ($count &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($num % $count == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $count-- ;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">isprime</span>(<span class="params">$num</span>) </span>&#123;</span><br><span class="line">    $count = (int) sqrt($num);</span><br><span class="line">    $i = <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">while</span> ($i &lt;= $count) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($num % $i == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $i++ ;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$start = microtime(<span class="literal">true</span>);</span><br><span class="line"><span class="keyword">for</span> ($i = <span class="number">2</span>; $i &lt; <span class="number">100000</span>; $i++) &#123;</span><br><span class="line">    isprime($i);</span><br><span class="line">&#125;</span><br><span class="line">echo (microtime(<span class="literal">true</span>) - $start) * <span class="number">1000</span> .<span class="string">"\n"</span>;</span><br><span class="line"></span><br><span class="line">http:<span class="comment">//blog.qicunshang.com/2018/02/09/%E4%B8%80%E6%AC%A1%E5%85%B3%E4%BA%8E%E7%B4%A0%E6%95%B0while%E5%BE%AA%E7%8E%AF%E7%9A%84%E5%88%86%E6%9E%90/</span></span><br></pre></td></tr></table></figure>
<p><a href="https://github.com/BYVoid/OpenCC" target="_blank" rel="noopener">繁体简体互转 OpenCC-PHP 扩展</a></p>
<p><a href="https://github.com/peinhu/aetherupload-laravel" target="_blank" rel="noopener">超大文件上传</a></p>
<p><a href="https://learnku.com/articles/34568#replies" target="_blank" rel="noopener">AetherUpload 视频上传过程</a></p>
<p><a href="https://github.com/Hanson/foundation-sdk" target="_blank" rel="noopener">高德地图 SDK https://github.com/Hanson/gaode-sdk </a></p>
<p><a href="https://dashboard.zaoshu.io/" target="_blank" rel="noopener">云爬虫</a></p>
<p> Laravel 插件 PhpSpreadSheet 使用总结 <a href="https://phpspreadsheet.readthedocs.io/en/latest/topics/autofilters/" target="_blank" rel="noopener">https://phpspreadsheet.readthedocs.io/en/latest/topics/autofilters/</a>   <a href="https://learnku.com/articles/29608" target="_blank" rel="noopener">https://learnku.com/articles/29608</a><br><a href="https://learnku.com/articles/30048" target="_blank" rel="noopener">https://learnku.com/articles/30048</a></p>
<p>PHP 速查表 <a href="https://free-andy.github.io/php-dict" target="_blank" rel="noopener">https://free-andy.github.io/php-dict</a>  <a href="https://github.com/free-andy/php-dict" target="_blank" rel="noopener">https://github.com/free-andy/php-dict</a></p>
<p>plaidCTF两道web题目writeup <a href="http://blog.wonderkun.cc/2019/04/15/plaidCTF%E4%B8%A4%E9%81%93web%E9%A2%98%E7%9B%AEwriteup/" target="_blank" rel="noopener">http://blog.wonderkun.cc/2019/04/15/plaidCTF%E4%B8%A4%E9%81%93web%E9%A2%98%E7%9B%AEwriteup/</a></p>
<p>ctf <a href="https://www.yof3ng.xyz/" target="_blank" rel="noopener">https://www.yof3ng.xyz/</a></p>
<p>PHP中的危险函数和伪协议<a href="https://anemone.top/php-PHP%E4%B8%AD%E7%9A%84%E5%8D%B1%E9%99%A9%E5%87%BD%E6%95%B0%E5%92%8C%E4%BC%AA%E5%8D%8F%E8%AE%AE/" target="_blank" rel="noopener">https://anemone.top/php-PHP%E4%B8%AD%E7%9A%84%E5%8D%B1%E9%99%A9%E5%87%BD%E6%95%B0%E5%92%8C%E4%BC%AA%E5%8D%8F%E8%AE%AE/</a></p>
<p>几个比较有意思的逻辑问题 <a href="https://www.xuejiayuan.net/blog/1d15a4dfae8747a3b263052ec024aae2" target="_blank" rel="noopener">https://www.xuejiayuan.net/blog/1d15a4dfae8747a3b263052ec024aae2</a></p>
<p><a href="https://github.com/Lysice/laravel-sms" target="_blank" rel="noopener">Laravel-sms 阿里云短信扩展包</a></p>
<p><a href="https://github.com/zzjzz9266a/91porn_php" target="_blank" rel="noopener">91porn爬虫php版本</a></p>
<p><a href="https://github.com/yan68/xcrawler" target="_blank" rel="noopener">快速、简洁且强大的PHP爬虫框架 </a></p>
<p><a href="https://learnku.com/articles/34879" target="_blank" rel="noopener">CentOS7 轻松部署 Laravel 应用</a></p>
<p><a href="https://learnku.com/php/t/34358#replies" target="_blank" rel="noopener">高性能优化 PHP-FPM</a></p>
<p><a href="https://shiwenyuan.github.io/post/ck1irc5wo000nq2fyg1yi9twn.html" target="_blank" rel="noopener">开发自己的composer包</a></p>
<p><a href="https://learnku.com/php/t/34358" target="_blank" rel="noopener">高性能优化 PHP-FPM</a></p>
<p><a href="https://learnku.com/articles/31108#replies" target="_blank" rel="noopener">大文件传输解决方案：分片上传 / 下载限速</a></p>
<p><a href="https://learnku.com/articles/34415" target="_blank" rel="noopener">开源访问控制框架</a></p>
<p><a href="https://learnku.com/articles/34415" target="_blank" rel="noopener">权限控制库 Casbin</a></p>
<p><a href="https://learnku.com/articles/34416" target="_blank" rel="noopener">数据结构之链表</a></p>
<p><a href="https://learnku.com/articles/34368" target="_blank" rel="noopener">深入理解计算机系统学习</a></p>
<p><a href="https://learnku.com/articles/34360" target="_blank" rel="noopener">laragon 简单好用的 PHP 环境</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/79502041" target="_blank" rel="noopener">搭建高性能的私有 Composer 镜像服务</a></p>
<p><a href="https://learnku.com/articles/30371" target="_blank" rel="noopener">PHP socket 的简单理解</a></p>
<p><a href="https://learnku.com/articles/33952" target="_blank" rel="noopener">phpstudy apache 配置 https 证书</a></p>
<p><a href="https://learnku.com/articles/33806" target="_blank" rel="noopener">PHP 三年模拟五年面试之一网打尽系列（4）—– MySQL 高级</a></p>
<p><a href="https://learnku.com/articles/34057" target="_blank" rel="noopener">PHP 中四大经典排序算法</a></p>
<p><a href="https://learnku.com/articles/25922?order_by=vote_count&amp;" target="_blank" rel="noopener">Laravel-snappy 生成 PDF 踩坑记录</a></p>
<p><a href="https://learnku.com/laravel/t/33857#reply108464" target="_blank" rel="noopener">Laravel Ignition 错误页面功能全解析</a></p>
<p><a href="https://php74-playground.baiguiren.com/?template=1" target="_blank" rel="noopener">PHP 7.4在线运行代码</a></p>
<p><a href="https://learnku.com/articles/25760" target="_blank" rel="noopener">PC 端微信扫码支付全过程</a></p>
<p><a href="https://github.com/viest/php-ext-excel-export" target="_blank" rel="noopener">PHP 高性能 Excel 扩展</a></p>
<p><a href="https://crontab.guru/" target="_blank" rel="noopener">crontab 定时任务直观地编辑</a></p>
<p><a href="https://learnku.com/articles/26282#replies" target="_blank" rel="noopener">接入 paypal PHP-sdk 支付宝支付 / 回调 / 退款全流程</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/03/微博十年了，你还玩吗/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/03/微博十年了，你还玩吗/" itemprop="url">微博十年了，你还玩吗?</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-03T11:16:43+08:00">
                2019-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  233 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>微博09年诞生，一晃10年过去了，记得我第一条微博是2012年4月23 <a href="https://weibo.com/2717930601/yfTTlFGr8" target="_blank" rel="noopener">https://weibo.com/2717930601/yfTTlFGr8</a> </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-4fffe89bcaf991d9?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-25b818577c4d062f?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>7年时间微博发了8万多条，我也是佩服自己。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-369c42d228a6c163?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>这周（8月28号）微博举行十周年活动，微博小秘书创建了微博十年的话题。<a href="https://weibo.com/aj/static/tenyears.html" target="_blank" rel="noopener">https://weibo.com/aj/static/tenyears.html</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-4bd5e7cd141377e5?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>微博转发300多万。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-ead6d2bc5c947b5d?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>玩微博这么久，挺后悔的一件事就是没有好好运营，没有成为某方面的大v，粉丝目前还没破万。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-83a1f862f4bf24bb?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>下面是我在公司拍的一些照片。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-9ba91d0d1b662cd3?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2eef766525e98b2b?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-0f15d477ebfec028?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-80f70891605bd30d?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p> <img src="https://upload-images.jianshu.io/upload_images/17817191-2ea133afd9197aa3?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-46cc8ab128284104?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-3e9c8dca1b4c1c57?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-7c32c3bf6a925e8d?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-5f889cac54052a12?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p> 还拍了个微博视频，地址<a href="https://weibo.com/2717930601/I4kyJE8E4" target="_blank" rel="noopener">https://weibo.com/2717930601/I4kyJE8E4</a> </p>
<p><a href="https://weibo.com/1642909335/I4gCrzR72" target="_blank" rel="noopener">https://weibo.com/1642909335/I4gCrzR72</a> </p>
<p>还上了个假的热搜。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-dadc1b54efc7ff4e?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-72bd26c9b40a78ec?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><strong>媒体总结的近十年的35部爆款剧，你看过多少？</strong></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-724edeec66dcf67d?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>下面的图片来自微博 </p>
<p><a href="https://weibo.com/6046360157/I4ilE6GL3" target="_blank" rel="noopener">https://weibo.com/6046360157/I4ilE6GL3</a> </p>
<p><a href="https://weibo.com/3031969212/I4iFCwLMM" target="_blank" rel="noopener">https://weibo.com/3031969212/I4iFCwLMM</a></p>
<p><a href="https://weibo.com/1385892075/I4jsF6AYU" target="_blank" rel="noopener">https://weibo.com/1385892075/I4jsF6AYU</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-376f8c95b07af5bf?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-e6dbfda915f61edd?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-19572ec22fb1a2fe?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-be99a00b4769614e?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-c9079a647da4a65b?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-635cfa89c8b91d93?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-5814306eaa57d2f1?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p> 苹果我还没领。。。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-65113eeee15cbac9?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-eacb9fe49a0d7ede?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2b82ac0dcbf182da?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image"></p>
<p>最后祝福微博，下个十年更精彩。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/09/02/知识星球精华/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/02/知识星球精华/" itemprop="url">知识星球精华</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-02T11:14:52+08:00">
                2019-09-02
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  30 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><a href="https://github.com/ChrisLinn/greyhame-2017" target="_blank" rel="noopener">知识星球黑客漏洞挖掘”灰袍技能” 2017 精华</a></p>
<p><a href="https://github.com/wbsabc/zsxq-spider" target="_blank" rel="noopener">爬取知识星球，并制作 PDF 电子书</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/26/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/26/">26</a><span class="page-number current">27</span><a class="page-number" href="/page/28/">28</a><span class="space">&hellip;</span><a class="page-number" href="/page/39/">39</a><a class="extend next" rel="next" href="/page/28/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
